Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit bdce974

Browse files
authored
Merge pull request #205 from asigloo/bugfix/add-optionvalue-and-optionkey-properties
feat(select): optionValue and optionKey
2 parents b7550af + b349b8b commit bdce974

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

dev/typescript/App.vue

+13-12
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,23 @@ export default defineComponent({
161161
value: 'the-last-of-us',
162162
options: [
163163
{
164-
key: 'the-last-of-us',
165-
value: 'The Last of Us II',
164+
value: 'the-last-of-us',
165+
label: 'The Last of Us II',
166166
},
167167
{
168-
key: 'death-stranding',
169-
value: 'Death Stranding',
168+
value: 'death-stranding',
169+
label: 'Death Stranding',
170170
},
171171
{
172-
key: 'nier-automata',
173-
value: 'Nier Automata',
172+
value: 'nier-automata',
173+
label: 'Nier Automata',
174174
},
175175
],
176176
}),
177177
console: SelectField({
178178
label: 'Console (Async Options)',
179179
customClass: 'w-1/2 pr-4',
180+
optionValue: 'console',
180181
options: consoleOptions.value,
181182
}),
182183
steps: NumberField({
@@ -256,16 +257,16 @@ export default defineComponent({
256257
try {
257258
consoleOptions.value = await mockAsync(true, 4000, [
258259
{
259-
key: 'playstation',
260-
value: 'Playstation',
260+
console: 'playstation',
261+
label: 'Playstation',
261262
},
262263
{
263-
key: 'nintendo',
264-
value: 'Nintendo',
264+
console: 'nintendo',
265+
label: 'Nintendo',
265266
},
266267
{
267-
key: 'xbox',
268-
value: 'Xbox',
268+
console: 'xbox',
269+
label: 'Xbox',
269270
},
270271
]);
271272
} catch (e) {

src/components/select-input/SelectInput.vue

+10-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@ export default defineComponent({
3232
return props?.control?.options;
3333
});
3434
35-
const options = formattedOptions.value.map(({ key, value, disabled }) =>
36-
h('option', { key, value: key, disabled }, value),
35+
const options = formattedOptions.value.map(option =>
36+
h(
37+
'option',
38+
{
39+
key: option[props.control.optionValue],
40+
value: option[props.control.optionValue],
41+
disabled: option.disabled,
42+
},
43+
option[props.control.optionLabel],
44+
),
3745
);
3846
return [
3947
h(

src/core/factories.ts

+4
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,15 @@ export const NumberField = ({
127127
export const SelectField = ({
128128
options = [],
129129
value,
130+
optionValue = 'value',
131+
optionLabel = 'label',
130132
...rest
131133
}: Partial<SelectInput>): SelectInput => ({
132134
...FieldBase(rest),
133135
value,
134136
options,
137+
optionValue,
138+
optionLabel,
135139
type: FieldTypes.SELECT,
136140
});
137141

src/core/models.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ export type NumberInput = InputBase & {
9191
export type SelectInput<T = boolean | string> = InputBase & {
9292
type: FieldTypes.SELECT;
9393
value: T;
94-
options?: { key: string; value: string; disabled?: boolean }[];
94+
optionValue: string;
95+
optionLabel: string;
96+
options?: { label: string; value: string; disabled?: boolean }[];
9597
};
9698

9799
export type TextAreaInput = InputBase & {

0 commit comments

Comments
 (0)