Skip to content

Commit

Permalink
Merge branch 'main' of github.com:equinor/webviz into endpoint-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv committed Sep 3, 2024
2 parents 6ab56a8 + d59a635 commit ebb65cb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions frontend/src/lib/components/Select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const Select = withDefaults<SelectProps>()(defaultProps, (props) => {
const [filteredOptions, setFilteredOptions] = React.useState<SelectOption[]>(props.options);
const [selectionAnchor, setSelectionAnchor] = React.useState<number | null>(null);
const [selectedOptionValues, setSelectedOptionValues] = React.useState<string[]>([]);
const [prevPropsValue, setPrevPropsValue] = React.useState<string[]>([]);
const [prevPropsValue, setPrevPropsValue] = React.useState<string[] | undefined>(undefined);
const [currentFocusIndex, setCurrentFocusIndex] = React.useState<number>(0);
const [virtualizationStartIndex, setVirtualizationStartIndex] = React.useState<number>(0);
const [reportedVirtualizationStartIndex, setReportedVirtualizationStartIndex] = React.useState<number>(0);
Expand All @@ -84,9 +84,10 @@ export const Select = withDefaults<SelectProps>()(defaultProps, (props) => {
filterOptions(newOptions, filterString);
}

if (props.value && !isEqual(props.value, prevPropsValue)) {
setSelectedOptionValues([...props.value]);
setPrevPropsValue([...props.value]);
if (!isEqual(props.value, prevPropsValue)) {
setPrevPropsValue(props.value ? [...props.value] : undefined);
setSelectedOptionValues(props.value ? [...props.value] : []);
setSelectionAnchor(props.value ? filteredOptions.findIndex((option) => option.value === props.value[0]) : null);
}

const handleOnChange = React.useCallback(
Expand Down Expand Up @@ -344,6 +345,7 @@ export const Select = withDefaults<SelectProps>()(defaultProps, (props) => {

setCurrentFocusIndex(newCurrentKeyboardFocusIndex);
setVirtualizationStartIndex(newVirtualizationStartIndex);
setSelectionAnchor(newFilteredOptions.findIndex((option) => option.value === selectedOptionValues[0]));
}

function handleFilterChange(event: React.ChangeEvent<HTMLInputElement>) {
Expand Down

0 comments on commit ebb65cb

Please sign in to comment.