fix: option vide rendue uniquement si emptyOptionLabel non vide (#36)
All checks were successful
Release / release (push) Successful in 1m11s
All checks were successful
Release / release (push) Successful in 1m11s
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [ ] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié Co-authored-by: kevin <kevin@yuno.malio.fr> Co-authored-by: Kevin Boudet <kevin@yuno.malio.fr> Reviewed-on: #36 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #36.
This commit is contained in:
@@ -88,11 +88,46 @@ describe('MalioSelect', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
await wrapper.get('button').trigger('click')
|
await wrapper.get('button').trigger('click')
|
||||||
await wrapper.findAll('li')[2].trigger('click')
|
await wrapper.findAll('li')[1].trigger('click')
|
||||||
|
|
||||||
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual(['be'])
|
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual(['be'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('does not render empty option when emptyOptionLabel is empty', async () => {
|
||||||
|
const wrapper = mount(SelectForTest, {
|
||||||
|
props: {
|
||||||
|
modelValue: null,
|
||||||
|
options: [
|
||||||
|
{label: 'AM', value: 'am'},
|
||||||
|
{label: 'PM', value: 'pm'},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await wrapper.get('button').trigger('click')
|
||||||
|
|
||||||
|
const items = wrapper.findAll('li[role="option"]')
|
||||||
|
expect(items).toHaveLength(2)
|
||||||
|
expect(items[0].text()).toBe('AM')
|
||||||
|
expect(items[1].text()).toBe('PM')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders empty option when emptyOptionLabel is provided', async () => {
|
||||||
|
const wrapper = mount(SelectForTest, {
|
||||||
|
props: {
|
||||||
|
modelValue: null,
|
||||||
|
options: [{label: 'AM', value: 'am'}],
|
||||||
|
emptyOptionLabel: 'Choisir...',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await wrapper.get('button').trigger('click')
|
||||||
|
|
||||||
|
const items = wrapper.findAll('li[role="option"]')
|
||||||
|
expect(items).toHaveLength(2)
|
||||||
|
expect(items[0].text()).toBe('Choisir...')
|
||||||
|
})
|
||||||
|
|
||||||
it('renders the empty option with muted text style', async () => {
|
it('renders the empty option with muted text style', async () => {
|
||||||
const wrapper = mount(SelectForTest, {
|
const wrapper = mount(SelectForTest, {
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
@@ -208,10 +208,10 @@ const buttonId = `custom-select-btn-${uid}`
|
|||||||
const listboxId = `custom-select-listbox-${uid}`
|
const listboxId = `custom-select-listbox-${uid}`
|
||||||
const listRef = ref<HTMLElement | null>(null)
|
const listRef = ref<HTMLElement | null>(null)
|
||||||
const listHeight = ref(0)
|
const listHeight = ref(0)
|
||||||
const normalizedOptions = computed<Option[]>(() => [
|
const normalizedOptions = computed<Option[]>(() => {
|
||||||
{label: props.emptyOptionLabel, value: null},
|
if (!props.emptyOptionLabel) return props.options
|
||||||
...props.options,
|
return [{label: props.emptyOptionLabel, value: null}, ...props.options]
|
||||||
])
|
})
|
||||||
const mergedGroupClass = computed(() =>
|
const mergedGroupClass = computed(() =>
|
||||||
twMerge('relative w-full', props.minWidth, props.maxWidth, props.groupClass),
|
twMerge('relative w-full', props.minWidth, props.maxWidth, props.groupClass),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user