Skip to content

Commit

Permalink
feat(select-slist): enhance selection list
Browse files Browse the repository at this point in the history
  • Loading branch information
xav-car committed Jan 30, 2025
1 parent 3259c60 commit f968812
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 52 deletions.
30 changes: 16 additions & 14 deletions addon/components/pix-select-list.hbs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<ul role="listbox" id={{@listId}} class="pix-select_list" ...attributes>
<li
class="pix-select-list-category__option{{unless
@value
' pix-select-list-category__option--selected'
}}{{unless @displayDefaultOption ' pix-select-list-category__option--hidden'}}"
role="option"
tabindex={{if this.isDefaultOptionHidden "-1" "0"}}
aria-selected={{if @value "false" "true"}}
{{on "click" (fn @onChange @defaultOption)}}
{{on-enter-action (fn @onChange @defaultOption)}}
{{on-space-action (fn @onChange @defaultOption)}}
>
{{@defaultOptionValue}}
</li>
{{#if @displayDefaultOption}}
<li
class="pix-select-list-category__option pix-select-list-category__option--default{{unless
@value
' pix-select-list-category__option--selected'
}}"
role="option"
tabindex={{if this.isDefaultOptionHidden "-1" "0"}}
aria-selected={{if @value "false" "true"}}
{{on "click" (fn @onChange @defaultOption)}}
{{on-enter-action (fn @onChange @defaultOption)}}
{{on-space-action (fn @onChange @defaultOption)}}
>
{{@defaultOptionValue}}
</li>
{{/if}}
{{#if this.results}}
{{#if this.displayCategory}}
{{#each this.results as |element index|}}
Expand Down
51 changes: 24 additions & 27 deletions addon/styles/_pix-select-list.scss
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
@use "pix-design-tokens/typography";

.pix-select_list {
padding: var(--pix-spacing-2x);
border-top: 1px solid var(--pix-neutral-20);

--border-radius-2x: var(--pix-spacing-2x);

display: flex;
flex-direction: column;
gap: var(--pix-spacing-1x);
padding: var(--pix-spacing-2x) var(--pix-spacing-1x);
}

.pix-select-list-category {
display: flex;
flex-direction: column;
gap: var(--pix-spacing-1x);
margin: 0;
padding: 0;
list-style: none;

&__name {
@extend %pix-body-s;

padding: var(--pix-spacing-4x) var(--pix-spacing-6x) var(--pix-spacing-2x) var(--pix-spacing-4x);
color: var(--pix-neutral-500);
text-transform: uppercase;
padding: var(--pix-spacing-1x) var(--pix-spacing-3x);
color: var(--pix-neutral-800);
font-weight: var(--pix-font-bold);
text-transform: capitalize;
background-color: var(--pix-neutral-20);
border-radius: 0.25rem;
}

&__option {
@extend %pix-body-s;

position: relative;
padding: var(--pix-spacing-2x) var(--pix-spacing-8x) var(--pix-spacing-2x) var(--pix-spacing-4x);
padding: var(--pix-spacing-2x) var(--pix-spacing-10x) var(--pix-spacing-2x) var(--pix-spacing-3x);
color: var(--pix-neutral-900);
border-radius: 8px;
border-radius: 0.25rem;

&:nth-child(even) {
background-color: var(--pix-neutral-20);
&:hover {
background-color: rgba(var(--pix-neutral-100-inline), 0.60);
outline: none;
cursor: pointer;
}

&:hover,
&:focus {
background-color: var(--pix-primary-10);
outline: none;
Expand All @@ -43,27 +49,18 @@
svg {
position: absolute;
top: 50%;
right: var(--pix-spacing-2x);
right: var(--pix-spacing-3x);
transform: translateY(-50%);
visibility: hidden;
opacity: 0;
}

&--selected {
align-items: center;
color: var(--pix-primary-900);
font-weight: var(--pix-font-bold);
background-color: var(--pix-primary-10);

svg {
visibility: visible;
opacity: 1;
}
}

&--hidden {
height: 0;
padding-top: 0;
padding-bottom: 0;
visibility: hidden;
&--default {
margin-bottom: var(--pix-spacing-1x);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion addon/styles/_pix-select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

&__search {
display: flex;
margin: var(--pix-spacing-4x) var(--pix-spacing-6x);
margin: var(--pix-spacing-2x) var(--pix-spacing-3x);
color: var(--pix-neutral-100);
border-bottom: 2px solid var(--pix-neutral-100);
border-radius: var(--pix-spacing-1x) var(--pix-spacing-1x) 0 0;
Expand Down
11 changes: 6 additions & 5 deletions tests/dummy/app/controllers/select-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ export default class SelectPage extends Controller {

get options() {
return [
{ value: '1', label: 'Figues' },
{ value: '3', label: 'Fraises' },
{ value: '2', label: 'Bananes' },
{ value: '4', label: 'Mangues' },
{ value: '5', label: 'Kaki' },
{ value: '1', label: 'Figues', category: 'rouge' },
{ value: '3', label: 'Fraises', category: 'rouge' },
{ value: '2', label: 'Bananes', category: 'jaune' },
{ value: '4', label: 'Mangues', category: 'jaune' },
{ value: '5', label: 'Kaki', category: 'vert' },
{
value: '6',
label: 'Asiminier trilobé oblong vert (à ne pas confondre avec la papaye)',
category: 'vert'
},
];
}
Expand Down
8 changes: 3 additions & 5 deletions tests/integration/components/pix-structure-switcher-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ module('Integration | Component | pix-structure-switcher', function (hooks) {
const button = screen.getByRole('button', { name: 'Changer de structure' });
await userEvent.click(button);

const hiddenDefaultOption = await screen.findByRole('option', {
selected: true,
hidden: true,
});
// then
assert.strictEqual(hiddenDefaultOption.tabIndex, -1);
assert.notOK(screen.queryByRole('option', {
name : 'Changer de structure'
}));
});
});

Expand Down

0 comments on commit f968812

Please sign in to comment.