Skip to content
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
139 changes: 70 additions & 69 deletions packages/lib/src/select/Listbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ import scrollbarStyles from "../styles/scroll";
import { FlattenedItem, ListboxProps, ListOptionGroupType, ListOptionType } from "./types";
import CheckboxContext from "../checkbox/CheckboxContext";
import { Virtuoso, VirtuosoHandle } from "react-virtuoso";
import DxcBleed from "../bleed/Bleed";

const ListboxContainer = styled.div<{
height?: ListboxProps["virtualizedHeight"];
}>`
box-sizing: border-box;
max-height: 304px;
height: ${(props) => (props.height ? props.height : undefined)};
padding: var(--spacing-padding-xxs) var(--spacing-padding-none);
background-color: var(--color-bg-neutral-lightest);
border: var(--border-width-s) var(--border-style-default) var(--border-color-neutral-medium);
border-radius: var(--border-radius-s);
box-shadow: var(--shadow-200);
color: var(--color-fg-neutral-dark);
font-family: var(--typography-font-family);
font-size: var(--typography-label-m);
Expand Down Expand Up @@ -219,54 +215,57 @@ const VirtualizedListbox = ({
};

return (
<ListboxContainer
height={virtualizedHeight}
id={id}
onClick={(event) => {
event.stopPropagation();
}}
onMouseDown={(event) => {
event.preventDefault();
}}
style={styles}
>
<Virtuoso
ref={virtuosoRef}
style={{ height: "100%" }}
totalCount={flattenedOptions.length}
initialTopMostItemIndex={
!multiple && currentValue
? {
index:
flattenedOptions.findIndex((item) => item.type === "option" && item.option.value === currentValue) ??
0,
align: "center",
behavior: "auto",
}
: 0
}
itemContent={(index) => renderItem(index)}
components={{
List: forwardRef((props, ref) => (
<div
ref={ref}
role="listbox"
aria-labelledby={ariaLabelledBy}
aria-multiselectable={multiple}
id={id}
{...props}
/>
)),
Header: () =>
isSearchEmpty ? (
<OptionsSystemMessage>
<DxcIcon icon="search_off" />
{translatedLabels.select.noMatchesErrorMessage}
</OptionsSystemMessage>
) : null,
<DxcBleed horizontal={"var(--spacing-padding-xs)"}>
Comment thread
PelayoFelgueroso marked this conversation as resolved.
<ListboxContainer
height={virtualizedHeight}
id={id}
onClick={(event) => {
event.stopPropagation();
}}
onMouseDown={(event) => {
event.preventDefault();
}}
/>
</ListboxContainer>
style={styles}
>
<Virtuoso
ref={virtuosoRef}
style={{ height: "100%" }}
totalCount={flattenedOptions.length}
initialTopMostItemIndex={
!multiple && currentValue
? {
index:
flattenedOptions.findIndex(
(item) => item.type === "option" && item.option.value === currentValue
) ?? 0,
align: "center",
behavior: "auto",
}
: 0
}
itemContent={(index) => renderItem(index)}
components={{
List: forwardRef((props, ref) => (
<div
ref={ref}
role="listbox"
aria-labelledby={ariaLabelledBy}
aria-multiselectable={multiple}
id={id}
{...props}
/>
)),
Header: () =>
isSearchEmpty ? (
<OptionsSystemMessage>
<DxcIcon icon="search_off" />
{translatedLabels.select.noMatchesErrorMessage}
</OptionsSystemMessage>
) : null,
}}
/>
</ListboxContainer>
</DxcBleed>
);
};

Expand Down Expand Up @@ -435,23 +434,25 @@ const NonVirtualizedListbox = ({
}, [visualFocusIndex]);

return (
<ListboxContainer
aria-labelledby={ariaLabelledBy}
aria-multiselectable={multiple}
id={id}
onClick={(event) => {
event.stopPropagation();
}}
onMouseDown={(event) => {
event.preventDefault();
}}
ref={listboxRef}
role="listbox"
style={styles}
>
{getFirstItem()}
{options.map(mapOptionFunc)}
</ListboxContainer>
<DxcBleed horizontal={"var(--spacing-padding-xs)"}>
<ListboxContainer
aria-labelledby={ariaLabelledBy}
aria-multiselectable={multiple}
id={id}
onClick={(event) => {
event.stopPropagation();
}}
onMouseDown={(event) => {
event.preventDefault();
}}
ref={listboxRef}
role="listbox"
style={styles}
>
{getFirstItem()}
{options.map(mapOptionFunc)}
</ListboxContainer>
</DxcBleed>
);
};

Expand Down
Loading
Loading