Skip to content

Commit

Permalink
fix: slot type of c-input is enum member metadata, not raw enum numer…
Browse files Browse the repository at this point in the history
…ic value
  • Loading branch information
ascott18 committed Dec 4, 2024
1 parent ce74566 commit 066198e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<c-input :model="caseVm" for="status" variant="outlined">
<template #item="{ item, props }">
<v-list-item v-bind="props" :title="undefined">
{{ item.title }}: {{ item.value }}
{{ item.raw.displayName }}: {{ item.value }}
</v-list-item>
</template>
<template #selection="{ item }">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<template #item="item">
<span>{{
(() => {
//@ts-expect-error item is an enum number, cast to string should be invalid
//@ts-expect-error item.raw is enum metadata, cast to string should be invalid
item.item.raw as string;

return item.item.raw as number;
return item.item.raw.displayName as string;
})()
}}</span>
</template>
Expand Down
27 changes: 14 additions & 13 deletions src/coalesce-vue-vuetify3/src/components/input/c-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,24 @@ type InheritedProps = Omit<
| "active"
>;
type ProducesSelect<
type SelectSlotItemType<
TModel extends Model | DataSource | AnyArgCaller | undefined,
TFor extends ForSpec<TModel>
> = TFor extends EnumValue | (CollectionValue & { itemType: EnumValue })
? true
? EnumMember
: TFor extends string
? TFor extends keyof EnumTypeLookup
? true
? EnumMember
: TModel extends Model
? TFor extends PropNames<TModel["$metadata"]>
? TModel["$metadata"]["props"][TFor] extends
| EnumValue
| (CollectionValue & { itemType: EnumValue })
? true
: false
: false
: false
: false;
? EnumMember
: never
: never
: never
: never;
// Duplicated from Vuetify because Vuetify doesn't export this type
// https://github.com/vuetifyjs/vuetify/blob/a36dfb8c4764376ce2af0d994983238dbd96f5bf/packages/vuetify/src/composables/list-items.ts#L10
Expand All @@ -100,21 +100,21 @@ interface ListItem<T = any> {
type _InheritedSlots<
TModel extends Model | DataSource | AnyArgCaller | undefined,
TFor extends ForSpec<TModel>
> = ProducesSelect<TModel, TFor> extends true
? // These slots for v-select/v-autocomplete are duplicated from Vuetify because Vuetify doesn't export their types correctly.
> = SelectSlotItemType<TModel, TFor> extends {}
? // These slots for v-select/v-autocomplete are duplicated from Vuetify because Vuetify doesn't export their types correctly for generic components.
Omit<VInput["$slots"] & VField["$slots"], "default"> & {
item?(props: {
item: ListItem<_ValueType<TModel, TFor>>;
item: ListItem<SelectSlotItemType<TModel, TFor>>;
index: number;
props: Record<string, unknown>;
}): any;
chip?(props: {
item: ListItem<_ValueType<TModel, TFor>>;
item: ListItem<SelectSlotItemType<TModel, TFor>>;
index: number;
props: Record<string, unknown>;
}): any;
selection?(props: {
item: ListItem<_ValueType<TModel, TFor>>;
item: ListItem<SelectSlotItemType<TModel, TFor>>;
index: number;
}): any;
}
Expand Down Expand Up @@ -162,6 +162,7 @@ import {
EnumValue,
CollectionValue,
EnumTypeLookup,
EnumMember,
} from "coalesce-vue";
import CSelect from "./c-select.vue";
Expand Down

0 comments on commit 066198e

Please sign in to comment.