-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add new useVirtualFocus hook, for use in Combobox #2394
Merged
Merged
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
795ed37
Add new useVirtualFocus hook, for use in Combobox. Might be useful fo…
it-vegard 59ce795
Create filteredOptionsUtils, which has utiltity functions for creatin…
it-vegard 0b080c8
Get rid of data-value, and use filteredOptionsMap to look up the valu…
it-vegard 0e14802
Using useState instead of useRef to handle filteredOptionsRef
it-vegard fd88897
Merge branch 'main' into feature/useVirtualFocus-hook-for-combobox
it-vegard d12190f
Added changeset
it-vegard a2f51db
Merge branch 'main' into feature/useVirtualFocus-hook-for-combobox
it-vegard 26c0381
Merge branch 'main' into feature/useVirtualFocus-hook-for-combobox
it-vegard fff5c51
Force option id to be lower case, to avoid different casing from bein…
it-vegard 2122430
Merge branch 'feature/useVirtualFocus-hook-for-combobox' of https://g…
it-vegard 7e52f24
Fix bug where it was not possible to select multiple custom (new) opt…
it-vegard 148bdae
Switch to use toLocalLowerCase and remove uneccessary use of string l…
it-vegard 3bfb3be
type mismatch
it-vegard 7f5c9ff
Merge branch 'main' into feature/useVirtualFocus-hook-for-combobox
it-vegard c0d65ce
Clean up types - reuse from ComboboxProps type definition, and fix re…
it-vegard 72edee9
Rename filteredOptionsRef variable returned from filteredOptionsConte…
it-vegard 3096696
Expose virtualFocus as an object through filteredOptionsContext, inst…
it-vegard 80b42da
Merge branch 'main' into feature/useVirtualFocus-hook-for-combobox
it-vegard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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}`.toLowerCase().trim() : ""; | ||
it-vegard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Liker denne filen, smart å trekke ut utils