Skip to content

Commit

Permalink
fix(listbox): add selected indicator (#785)
Browse files Browse the repository at this point in the history
* fix(listbox): add selected indicator

* fix(listbox): fix lint + snapshots

* fix(listbox): fix lint

* fix(listbox): fix comments
  • Loading branch information
LarryMatte authored and mmorin-equisoft committed Apr 17, 2024
1 parent c84a73c commit 129f3c4
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/react/src/components/combobox/combobox.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ input + .c2 {
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand Down Expand Up @@ -655,6 +656,7 @@ input + .c2 {
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand Down Expand Up @@ -1129,6 +1131,7 @@ exports[`Combobox matches the snapshot (mobile) 1`] = `
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
Expand Down Expand Up @@ -1611,6 +1614,7 @@ input + .c2 {
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ input + .c2 {
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand All @@ -90,6 +91,16 @@ input + .c2 {
background-color: #DBDEE1;
}
.c10::before {
background-color: #006296;
content: '';
display: block;
height: 100%;
left: 0;
position: absolute;
width: 4px;
}
.c12 {
-webkit-align-items: center;
-webkit-box-align: center;
Expand All @@ -105,6 +116,7 @@ input + .c2 {
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand Down Expand Up @@ -526,6 +538,7 @@ input + .c2 {
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand All @@ -539,6 +552,16 @@ input + .c2 {
background-color: #DBDEE1;
}
.c12::before {
background-color: #006296;
content: '';
display: block;
height: 100%;
left: 0;
position: absolute;
width: 4px;
}
.c14 {
-webkit-align-items: center;
-webkit-box-align: center;
Expand All @@ -554,6 +577,7 @@ input + .c2 {
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand Down Expand Up @@ -945,6 +969,7 @@ exports[`Dropdown list matches the snapshot (mobile) 1`] = `
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
Expand All @@ -957,6 +982,16 @@ exports[`Dropdown list matches the snapshot (mobile) 1`] = `
background-color: #DBDEE1;
}
.c8::before {
background-color: #006296;
content: '';
display: block;
height: 100%;
left: 0;
position: absolute;
width: 4px;
}
.c10 {
-webkit-align-items: center;
-webkit-box-align: center;
Expand All @@ -972,6 +1007,7 @@ exports[`Dropdown list matches the snapshot (mobile) 1`] = `
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
Expand Down Expand Up @@ -1371,6 +1407,7 @@ input + .c2 {
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand All @@ -1384,6 +1421,16 @@ input + .c2 {
background-color: #DBDEE1;
}
.c11::before {
background-color: #006296;
content: '';
display: block;
height: 100%;
left: 0;
position: absolute;
width: 4px;
}
.c13 {
-webkit-align-items: center;
-webkit-box-align: center;
Expand All @@ -1399,6 +1446,7 @@ input + .c2 {
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand Down
16 changes: 16 additions & 0 deletions packages/react/src/components/listbox/listbox.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ exports[`Listbox Matches the snapshot (multiselect) 1`] = `
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand Down Expand Up @@ -172,6 +173,7 @@ exports[`Listbox Matches the snapshot (multiselect) 1`] = `
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand All @@ -198,6 +200,7 @@ exports[`Listbox Matches the snapshot (multiselect) 1`] = `
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand Down Expand Up @@ -422,6 +425,7 @@ exports[`Listbox Matches the snapshot 1`] = `
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand All @@ -448,6 +452,7 @@ exports[`Listbox Matches the snapshot 1`] = `
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand All @@ -459,6 +464,16 @@ exports[`Listbox Matches the snapshot 1`] = `
background-color: #DBDEE1;
}
.c5::before {
background-color: #006296;
content: '';
display: block;
height: 100%;
left: 0;
position: absolute;
width: 4px;
}
.c6 {
-webkit-align-items: center;
-webkit-box-align: center;
Expand All @@ -474,6 +489,7 @@ exports[`Listbox Matches the snapshot 1`] = `
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
padding-right: var(--spacing-1x);
-webkit-user-select: none;
-moz-user-select: none;
Expand Down
15 changes: 15 additions & 0 deletions packages/react/src/components/listbox/listbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ interface ListItemProps {
$isMobile: boolean;
$selected: boolean;
$focused: boolean;
$multiselect: boolean;
}

const Container = styled.div<ContainerProps>`
Expand Down Expand Up @@ -149,6 +150,7 @@ const ListItem = styled.li<ListItemProps>`
line-height: var(--size-1halfx);
min-height: var(--size-1halfx);
padding: var(--spacing-half) var(--spacing-2x);
position: relative;
${({ $isMobile }) => (!$isMobile && css`
padding-right: var(--spacing-1x);
Expand All @@ -171,6 +173,18 @@ const ListItem = styled.li<ListItemProps>`
border: 1px solid ${({ theme }) => theme.component['listbox-item-selected-border-color']};
}
`)}
${({ $selected, $multiselect }) => (!$multiselect && $selected && css`
&::before {
background-color: ${({ theme }) => theme.component['listbox-item-selected-border-color']};
content: '';
display: block;
height: 100%;
left: 0;
position: absolute;
width: 4px;
}
`)}
`;

const ListItemTextContainer = styled.span`
Expand Down Expand Up @@ -481,6 +495,7 @@ export const Listbox: ForwardRefExoticComponent<ListboxProps & RefAttributes<HTM
}}
role="option"
$selected={isOptionSelected(option)}
$multiselect={multiselect}
>
{multiselect ? (
<CustomCheckbox
Expand Down

0 comments on commit 129f3c4

Please sign in to comment.