Skip to content

Commit

Permalink
fix(Standalone Forms): support disabled option on Select component
Browse files Browse the repository at this point in the history
  • Loading branch information
gravitano committed Sep 4, 2023
1 parent 5b2e7df commit f382d09
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
21 changes: 16 additions & 5 deletions packages/forms/src/form-select/Select.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ function createItems(length = 5, additionalAttrs = {}) {
}));
}

const items = createItems()
const items = createItems();

const groupItems = createItems(5, {
options: createItems(5),
})
});

export default {
title: 'Experimental/Forms/Select',
Expand All @@ -31,7 +31,18 @@ export default {
},
},
args: {
options: items,
options: [
{
label: 'Choose',
value: '',
},
...items,
{
label: 'Disabled item',
value: 'x',
disabled: true,
},
],
},
} as Meta;

Expand Down Expand Up @@ -62,15 +73,15 @@ DefaultValue.args = {

export const OptionGroup = Template.bind({});
OptionGroup.args = {
options: groupItems
options: groupItems,
};

export const VModel: Story<typeof Select> = (args) => ({
components: {
Select,
},
setup() {
const value = ref('')
const value = ref('');
return {args, value};
},
template: `
Expand Down
4 changes: 2 additions & 2 deletions packages/forms/src/form-select/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ defineSlots<{
<SelectOptions :options="options" />
</select>
</div>
<p v-if="hint" class="v-input-hint">
<div v-if="hint" class="v-input-hint">
<slot name="hint">
{{ hint }}
</slot>
</p>
</div>
<div v-if="errorMessage" class="v-input-error" :class="errorClass">
<slot name="error">
{{ errorMessage }}
Expand Down
12 changes: 11 additions & 1 deletion packages/forms/src/input/SelectOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
export interface Option {
label: string;
value: string | number;
disabled?: boolean;
selected?: boolean;
options?: Option[];
}
Expand All @@ -21,11 +23,19 @@ withDefaults(defineProps<Props>(), {
v-for="(subOption, index) in option.options"
:key="index"
:value="subOption?.value || subOption"
:disabled="subOption?.disabled"
:selected="subOption?.selected"
>
{{ subOption?.label || subOption }}
</option>
</optgroup>
<option v-else :key="index" :value="option?.value || option">
<option
v-else
:key="index"
:value="option?.value || option"
:disabled="option?.disabled"
:selected="option?.selected"
>
{{ option?.label || option }}
</option>
</template>
Expand Down

0 comments on commit f382d09

Please sign in to comment.