| 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: admin malio <malio@yuno.malio.fr> Co-authored-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr> Reviewed-on: #90 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #90.
This commit is contained in:
@@ -6,6 +6,7 @@ import SelectCheckbox from './SelectCheckbox.vue'
|
||||
type Option = {
|
||||
label: string
|
||||
value: string | number
|
||||
color?: string
|
||||
}
|
||||
|
||||
type SelectCheckboxProps = {
|
||||
@@ -21,6 +22,7 @@ type SelectCheckboxProps = {
|
||||
textLabel?: string
|
||||
rounded?: string
|
||||
displayTag?: boolean
|
||||
maxTags?: number
|
||||
displaySelectAll?: boolean
|
||||
selectAllLabel?: string
|
||||
disabled?: boolean
|
||||
@@ -380,4 +382,63 @@ describe('MalioSelectCheckbox', () => {
|
||||
expect(msg.exists()).toBe(true)
|
||||
expect(msg.classes()).not.toContain('min-h-[1rem]')
|
||||
})
|
||||
|
||||
it('affiche tous les tags par défaut (maxTags non fourni)', () => {
|
||||
const wrapper = mount(SelectCheckboxForTest, {
|
||||
props: {modelValue: ['fr', 'be', 'ca'], options, displayTag: true},
|
||||
})
|
||||
|
||||
expect(wrapper.find('[data-test="tags-overflow"]').exists()).toBe(false)
|
||||
expect(wrapper.text()).toContain('France')
|
||||
expect(wrapper.text()).toContain('Belgique')
|
||||
expect(wrapper.text()).toContain('Canada')
|
||||
})
|
||||
|
||||
it('limite le nombre de tags affichés et ajoute un badge +N', () => {
|
||||
const manyOptions: Option[] = [
|
||||
{label: 'France', value: 'fr'},
|
||||
{label: 'Belgique', value: 'be'},
|
||||
{label: 'Canada', value: 'ca'},
|
||||
{label: 'Suisse', value: 'ch'},
|
||||
{label: 'Allemagne', value: 'de'},
|
||||
]
|
||||
const wrapper = mount(SelectCheckboxForTest, {
|
||||
props: {modelValue: ['fr', 'be', 'ca', 'ch', 'de'], options: manyOptions, displayTag: true, maxTags: 3},
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('France')
|
||||
expect(wrapper.text()).toContain('Belgique')
|
||||
expect(wrapper.text()).toContain('Canada')
|
||||
expect(wrapper.text()).not.toContain('Suisse')
|
||||
expect(wrapper.text()).not.toContain('Allemagne')
|
||||
expect(wrapper.get('[data-test="tags-overflow"]').text()).toBe('+2')
|
||||
})
|
||||
|
||||
it('n’affiche pas de badge +N quand le nombre de tags est sous la limite', () => {
|
||||
const wrapper = mount(SelectCheckboxForTest, {
|
||||
props: {modelValue: ['fr', 'be'], options, displayTag: true, maxTags: 3},
|
||||
})
|
||||
|
||||
expect(wrapper.find('[data-test="tags-overflow"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('applique la couleur de fond fournie par l’option', () => {
|
||||
const wrapper = mount(SelectCheckboxForTest, {
|
||||
props: {modelValue: ['fr'], options: [{label: 'France', value: 'fr', color: '#fde2e2'}], displayTag: true},
|
||||
})
|
||||
|
||||
const tag = wrapper.findAll('span.inline-flex')[0]
|
||||
expect(tag.attributes('style')).toContain('background-color')
|
||||
expect(tag.classes()).not.toContain('bg-m-bg')
|
||||
})
|
||||
|
||||
it('utilise bg-m-bg quand l’option n’a pas de couleur', () => {
|
||||
const wrapper = mount(SelectCheckboxForTest, {
|
||||
props: {modelValue: ['fr'], options, displayTag: true},
|
||||
})
|
||||
|
||||
const tag = wrapper.findAll('span.inline-flex')[0]
|
||||
expect(tag.classes()).toContain('bg-m-bg')
|
||||
expect(tag.attributes('style')).toBeFalsy()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -89,13 +89,25 @@
|
||||
:class="[label ? 'pt-1' : '']"
|
||||
>
|
||||
<span
|
||||
v-for="option in selectedOptions"
|
||||
v-for="option in visibleTags"
|
||||
:key="String(option.value)"
|
||||
class="inline-flex max-w-full items-center rounded-md border px-2 text-sm leading-none"
|
||||
:class="disabled ? 'border-black/40 text-black/60' : 'border-black text-black'"
|
||||
class="inline-flex max-w-full items-center rounded-md px-2 pt-[2px] pb-0 text-lg font-medium leading-[normal]"
|
||||
:class="[
|
||||
option.color ? '' : 'bg-m-bg',
|
||||
disabled ? 'text-black/60' : 'text-black',
|
||||
]"
|
||||
:style="option.color ? { backgroundColor: option.color } : undefined"
|
||||
>
|
||||
<span class="truncate pb-[2px]">{{ option.label }}</span>
|
||||
</span>
|
||||
<span
|
||||
v-if="hiddenTagsCount > 0"
|
||||
data-test="tags-overflow"
|
||||
class="inline-flex items-center rounded-md bg-m-bg px-2 pt-[2px] pb-0 text-lg font-medium leading-[normal]"
|
||||
:class="disabled ? 'text-black/60' : 'text-black'"
|
||||
>
|
||||
<span class="pb-[2px]">+{{ hiddenTagsCount }}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<span
|
||||
@@ -269,7 +281,8 @@ const {keyboardFocused, onFocus: onKbdFocus, onBlur: onKbdBlur} = useKbdFocusRin
|
||||
|
||||
type Option = {
|
||||
label: string;
|
||||
value: string | number
|
||||
value: string | number;
|
||||
color?: string
|
||||
}
|
||||
const props = withDefaults(defineProps<{
|
||||
modelValue?: Array<string | number>
|
||||
@@ -284,6 +297,7 @@ const props = withDefaults(defineProps<{
|
||||
textLabel?: string
|
||||
rounded?: string
|
||||
displayTag?: boolean
|
||||
maxTags?: number
|
||||
displaySelectAll?: boolean
|
||||
selectAllLabel?: string
|
||||
disabled?: boolean
|
||||
@@ -305,6 +319,7 @@ const props = withDefaults(defineProps<{
|
||||
textLabel: 'text-sm',
|
||||
rounded: 'rounded-md',
|
||||
displayTag: false,
|
||||
maxTags: 0,
|
||||
displaySelectAll: false,
|
||||
selectAllLabel: 'Tout sélectionner',
|
||||
disabled: false,
|
||||
@@ -347,6 +362,12 @@ const selectedOptions = computed(() =>
|
||||
const displayTags = computed(() =>
|
||||
props.displayTag && selectedOptions.value.length > 0,
|
||||
)
|
||||
const visibleTags = computed(() =>
|
||||
props.maxTags > 0 ? selectedOptions.value.slice(0, props.maxTags) : selectedOptions.value,
|
||||
)
|
||||
const hiddenTagsCount = computed(() =>
|
||||
props.maxTags > 0 ? Math.max(selectedOptions.value.length - props.maxTags, 0) : 0,
|
||||
)
|
||||
const shouldFloatLabel = computed(() =>
|
||||
isReadonly.value ? isOptionSelected.value : (isOpen.value || displayTags.value)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user