Skip to content

Commit

Permalink
fix(types): allow null model prop on all components that accept it
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 committed May 30, 2024
1 parent f6250c5 commit 7a2aa36
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export default defineComponent({
// If failed, try normalizing common separators to the same symbol in
// both the format string and user input.
if (!isValid(value)) {
const separatorRegex = /[\-\\\/\.]/g;
const separatorRegex = /[-\\/.]/g;
value = parse(
val.replace(separatorRegex, "-"),
this.internalFormat.replace(separatorRegex, "-"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ describe("CDatetimePicker", () => {
//@ts-expect-error non-date prop
() => <CDatetimePicker model={vm} for="long" />;

// Against models that might be null
() => (
<CDatetimePicker model={vm.referenceNavigation} for="systemDateOnly" />
);

() => (
<CDatetimePicker for="ComplexModel.dateTime" modelValue={selectedDate} />
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ defineOptions({
const props = withDefaults(
defineProps<{
/** An object owning the value to be edited that is specified by the `for` prop. */
model?: TModel;
model?: TModel | null;
/** A metadata specifier for the value being bound. One of:
* * A string with the name of the value belonging to `model`. E.g. `"startDate"`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ describe("CInput", () => {
//@ts-expect-error missing `for`
() => <CInput model={vm} />;

// Against models that might be null
() => <CInput model={vm.referenceNavigation} for="color" />;
//@ts-expect-error non-existent prop
() => <CInput model={vm.referenceNavigation} for="_anyString" />;

() => <CInput model={vm as any} for="_anyString" />;
() => <CInput model={model as Model} for="_anyString" />;
() => <CInput model={model as Model} for={vm.$metadata.props.color} />;
Expand Down
2 changes: 1 addition & 1 deletion src/coalesce-vue-vuetify3/src/components/input/c-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ defineOptions({
const props = withDefaults(
defineProps<{
/** An object owning the value to be edited that is specified by the `for` prop. */
model?: TModel;
model?: TModel | null;
/** A metadata specifier for the value being bound. One of:
* * A string with the name of the value belonging to `model`. E.g. `"firstName"`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ describe("CSelectValues", () => {
const vm = new ComplexModelViewModel();

() => <CSelectValues model={vm} for="mutablePrimitiveCollection" />;

// Against models that might be null
() => (
<CSelectValues
model={vm.referenceNavigation}
for="mutablePrimitiveCollection"
/>
);

() => (
<CSelectValues
model={vm}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defineOptions({
const props = defineProps<{
/** An object owning the value to be edited that is specified by the `for` prop. */
model?: TModel;
model?: TModel | null;
/** A metadata specifier for the value being bound. One of:
* * A string with the name of the value belonging to `model`. E.g. `"tags"`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ describe("CSelect", () => {
() => <CSelect model={vm} for="singleTestId" />;
() => <CSelect model={vm} for={vm.$metadata.props.singleTest} />;

// Against models that might be null
() => <CSelect model={vm.referenceNavigation} for="referenceNavigation" />;

// Binding to plain Models:
() => <CSelect model={model} for="singleTest" />;
() => <CSelect model={model} for="singleTestId" />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ defineSlots<{
const props = withDefaults(
defineProps<{
/** An object owning the value to be edited that is specified by the `for` prop. */
model?: TModel;
model?: TModel | null;
/** A metadata specifier for the value being bound. One of:
* * A string with the name of the value belonging to `model`. E.g. `"firstName"`.
Expand Down

0 comments on commit 7a2aa36

Please sign in to comment.