Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(listbox): add selected indicator #785

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading