-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
699 additions
and
748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@navikt/ds-react": patch | ||
--- | ||
|
||
Added useVirtualFocus hook - used in Combobox for now |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
@navikt/core/react/src/form/combobox/FilteredOptions/filtered-options-util.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const normalizeText = (text: string): string => | ||
typeof text === "string" ? text.toLocaleLowerCase().trim() : ""; | ||
|
||
const isPartOfText = (value, text) => | ||
normalizeText(text).startsWith(normalizeText(value ?? "")); | ||
|
||
const isValueInList = (value, list) => | ||
list?.find((listItem) => normalizeText(value) === normalizeText(listItem)); | ||
|
||
const getMatchingValuesFromList = (value, list) => | ||
list?.filter((listItem) => isPartOfText(value, listItem)); | ||
|
||
const getFilteredOptionsId = (comboboxId: string) => | ||
`${comboboxId}-filtered-options`; | ||
|
||
const getOptionId = (comboboxId: string, option: string) => | ||
`${comboboxId.toLocaleLowerCase()}-option-${option | ||
.replace(" ", "-") | ||
.toLocaleLowerCase()}`; | ||
|
||
const getAddNewOptionId = (comboboxId: string) => | ||
`${comboboxId}-combobox-new-option`; | ||
|
||
const getIsLoadingId = (comboboxId: string) => `${comboboxId}-is-loading`; | ||
|
||
const getNoHitsId = (comboboxId: string) => `${comboboxId}-no-hits`; | ||
|
||
export default { | ||
normalizeText, | ||
isPartOfText, | ||
isValueInList, | ||
getMatchingValuesFromList, | ||
getFilteredOptionsId, | ||
getAddNewOptionId, | ||
getOptionId, | ||
getIsLoadingId, | ||
getNoHitsId, | ||
}; |
Oops, something went wrong.