[#MUI-32] Création d'un composant saisie assistée (autocomplete) (#46)

| 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é

Reviewed-on: #46
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #46.
This commit is contained in:
2026-05-13 06:59:13 +00:00
committed by Autin
parent 9ed094ba86
commit b2e3a83bb9
12 changed files with 1949 additions and 75 deletions

View File

@@ -8,6 +8,7 @@ type Tab = {
key: string
label: string
icon?: string
disabled?: boolean
}
type TabListProps = {
@@ -134,4 +135,53 @@ describe('MalioTabList', () => {
expect(icons[0].props('icon')).toBe('mdi:home')
expect(icons[1].props('icon')).toBe('mdi:account')
})
it('sets disabled attribute and aria-disabled on disabled tabs', () => {
const disabledTabs: Tab[] = [
{key: 'a', label: 'A'},
{key: 'b', label: 'B', disabled: true},
]
const wrapper = mountComponent({tabs: disabledTabs})
const buttons = wrapper.findAll('[role="tab"]')
expect(buttons[1].attributes('disabled')).toBeDefined()
expect(buttons[1].attributes('aria-disabled')).toBe('true')
})
it('applies cursor-not-allowed on disabled tabs', () => {
const disabledTabs: Tab[] = [
{key: 'a', label: 'A'},
{key: 'b', label: 'B', disabled: true},
]
const wrapper = mountComponent({tabs: disabledTabs})
const buttons = wrapper.findAll('[role="tab"]')
expect(buttons[1].classes()).toContain('cursor-not-allowed')
expect(buttons[1].classes()).not.toContain('hover:text-m-primary/70')
})
it('does not emit update:modelValue when clicking a disabled tab', async () => {
const disabledTabs: Tab[] = [
{key: 'a', label: 'A'},
{key: 'b', label: 'B', disabled: true},
]
const wrapper = mountComponent({tabs: disabledTabs, modelValue: 'a'})
const buttons = wrapper.findAll('[role="tab"]')
await buttons[1].trigger('click')
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
})
it('does not change active tab in uncontrolled mode when clicking disabled tab', async () => {
const disabledTabs: Tab[] = [
{key: 'a', label: 'A'},
{key: 'b', label: 'B', disabled: true},
]
const wrapper = mountComponent({tabs: disabledTabs})
const buttons = wrapper.findAll('[role="tab"]')
await buttons[1].trigger('click')
expect(buttons[0].attributes('aria-selected')).toBe('true')
expect(buttons[1].attributes('aria-selected')).toBe('false')
})
})

View File

@@ -12,19 +12,23 @@
type="button"
:aria-selected="activeTab === tab.key"
:aria-controls="`${componentId}-panel-${tab.key}`"
:aria-disabled="!!tab.disabled"
:tabindex="activeTab === tab.key ? 0 : -1"
:disabled="tab.disabled"
:class="[
'flex items-center gap-[18px] text-[24px] font-medium transition-colors cursor-pointer',
'relative flex items-center gap-[18px] text-[24px] font-[600] transition-colors',
activeTab === tab.key
? 'border-b-2 border-m-primary text-m-primary font-bold outline-b'
: 'border-transparent text-m-primary/50 hover:text-m-primary/70',
? 'cursor-pointer text-m-primary after:content-[\'\'] after:absolute after:-bottom-[3px] after:left-0 after:right-0 after:h-[3px] after:bg-m-primary'
: tab.disabled
? 'cursor-not-allowed text-m-primary/50'
: 'cursor-pointer text-m-primary/50 hover:text-m-primary/70',
]"
@click="selectTab(tab.key)"
>
<IconifyIcon
v-if="tab.icon"
:icon="tab.icon"
:width="20"
:width="tab.iconSize ?? 24"
/>
{{ tab.label }}
</button>
@@ -53,6 +57,8 @@ type Tab = {
key: string
label: string
icon?: string
iconSize?: string
disabled?: boolean
}
const props = withDefaults(defineProps<{
@@ -79,6 +85,8 @@ const activeTab = computed(() =>
)
function selectTab(key: string) {
const tab = props.tabs.find(t => t.key === key)
if (tab?.disabled) return
if (!isControlled.value) {
localValue.value = key
}