@navikt/ds-react 5.12.5 → 5.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_docs.json +79 -3
- package/cjs/accordion/Accordion.js +2 -2
- package/cjs/accordion/AccordionHeader.js +1 -1
- package/cjs/accordion/AccordionItem.js +11 -14
- package/cjs/alert/Alert.js +2 -2
- package/cjs/chat/Bubble.js +1 -1
- package/cjs/chat/Chat.js +2 -2
- package/cjs/chips/Chips.js +1 -1
- package/cjs/chips/Removable.js +1 -1
- package/cjs/copybutton/CopyButton.js +2 -2
- package/cjs/date/datepicker/parts/Caption.js +2 -2
- package/cjs/date/datepicker/parts/DropdownCaption.js +1 -1
- package/cjs/date/datepicker/parts/HeadRow.js +1 -1
- package/cjs/date/datepicker/parts/Row.js +2 -2
- package/cjs/date/monthpicker/MonthCaption.js +1 -1
- package/cjs/date/parts/DateInput.js +1 -1
- package/cjs/date/utils/check-dates.js +1 -1
- package/cjs/date/utils/is-match.js +2 -2
- package/cjs/date/utils/parse-date.js +1 -1
- package/cjs/dropdown/Dropdown.js +10 -12
- package/cjs/dropdown/Menu/Divider.js +1 -1
- package/cjs/dropdown/Menu/GroupedList/GroupedHeading.js +1 -1
- package/cjs/expansion-card/ExpansionCardHeader.js +1 -1
- package/cjs/form/ReadOnlyIcon.js +1 -1
- package/cjs/form/Select.js +1 -1
- package/cjs/form/combobox/Combobox.js +6 -6
- package/cjs/form/combobox/ComboboxProvider.js +2 -2
- package/cjs/form/combobox/FilteredOptions/FilteredOptions.js +4 -4
- package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js +4 -4
- package/cjs/form/combobox/SelectedOptions/SelectedOptions.js +1 -1
- package/cjs/form/error-summary/ErrorSummary.js +2 -2
- package/cjs/form/error-summary/ErrorSummaryItem.js +1 -1
- package/cjs/form/search/Search.js +1 -1
- package/cjs/form/search/SearchButton.js +1 -1
- package/cjs/grid/Cell.js +1 -1
- package/cjs/grid/Grid.js +1 -1
- package/cjs/guide-panel/GuidePanel.js +1 -1
- package/cjs/internal-header/InternalHeaderButton.js +1 -1
- package/cjs/internal-header/InternalHeaderTitle.js +1 -1
- package/cjs/internal-header/InternalHeaderUser.js +1 -1
- package/cjs/internal-header/InternalHeaderUserButton.js +1 -1
- package/cjs/layout/bleed/Bleed.js +1 -1
- package/cjs/layout/content-container/ContentContainer.js +1 -1
- package/cjs/layout/grid/HGrid.js +1 -1
- package/cjs/layout/page/parts/PageBlock.js +1 -1
- package/cjs/layout/sidemal-test/AvatarPanel.js +1 -1
- package/cjs/layout/sidemal-test/Content.js +3 -3
- package/cjs/layout/sidemal-test/Filter.js +1 -1
- package/cjs/layout/sidemal-test/Intro.js +1 -1
- package/cjs/link-panel/LinkPanel.js +3 -3
- package/cjs/link-panel/LinkPanelDescription.js +1 -1
- package/cjs/link-panel/LinkPanelTitle.js +1 -1
- package/cjs/modal/ModalBody.js +1 -1
- package/cjs/modal/ModalFooter.js +1 -1
- package/cjs/modal/ModalHeader.js +1 -1
- package/cjs/pagination/PaginationItem.js +1 -1
- package/cjs/panel/Panel.js +1 -1
- package/cjs/popover/PopoverContent.js +1 -1
- package/cjs/read-more/ReadMore.js +12 -10
- package/cjs/skeleton/Skeleton.js +1 -1
- package/cjs/table/Body.js +1 -1
- package/cjs/table/ColumnHeader.js +1 -1
- package/cjs/table/DataCell.js +1 -1
- package/cjs/table/ExpandableRow.js +14 -13
- package/cjs/table/Header.js +1 -1
- package/cjs/table/Row.js +1 -1
- package/cjs/tabs/TabList.js +1 -1
- package/cjs/tabs/Tabs.js +1 -1
- package/cjs/tag/Tag.js +1 -1
- package/cjs/timeline/AxisLabels.js +1 -1
- package/cjs/timeline/TimelineRow.js +2 -2
- package/cjs/timeline/hooks/useTimelineRows.js +5 -3
- package/cjs/timeline/utils/timeline.js +1 -1
- package/cjs/timeline/zoom/ZoomButton.js +1 -1
- package/cjs/toggle-group/ToggleGroup.js +1 -1
- package/cjs/tooltip/Tooltip.js +12 -7
- package/cjs/typography/BodyLong.js +1 -1
- package/cjs/typography/ErrorMessage.js +1 -1
- package/cjs/typography/Ingress.js +1 -1
- package/cjs/util/RandomIcon.js +1 -1
- package/cjs/util/hooks/useCallbackRef.js +18 -0
- package/cjs/util/hooks/useControllableState.js +25 -0
- package/esm/accordion/Accordion.d.ts +1 -1
- package/esm/accordion/Accordion.js +2 -2
- package/esm/accordion/Accordion.js.map +1 -1
- package/esm/accordion/AccordionHeader.js +1 -1
- package/esm/accordion/AccordionHeader.js.map +1 -1
- package/esm/accordion/AccordionItem.d.ts +4 -0
- package/esm/accordion/AccordionItem.js +12 -15
- package/esm/accordion/AccordionItem.js.map +1 -1
- package/esm/alert/Alert.js +2 -2
- package/esm/alert/Alert.js.map +1 -1
- package/esm/chat/Bubble.js +1 -1
- package/esm/chat/Bubble.js.map +1 -1
- package/esm/chat/Chat.js +2 -2
- package/esm/chat/Chat.js.map +1 -1
- package/esm/chips/Chips.d.ts +2 -2
- package/esm/chips/Chips.js +1 -1
- package/esm/chips/Chips.js.map +1 -1
- package/esm/chips/Removable.js +1 -1
- package/esm/chips/Removable.js.map +1 -1
- package/esm/copybutton/CopyButton.js +2 -2
- package/esm/copybutton/CopyButton.js.map +1 -1
- package/esm/date/context/useSharedMonthContext.js.map +1 -1
- package/esm/date/datepicker/parts/Caption.js +2 -2
- package/esm/date/datepicker/parts/Caption.js.map +1 -1
- package/esm/date/datepicker/parts/DropdownCaption.js +1 -1
- package/esm/date/datepicker/parts/DropdownCaption.js.map +1 -1
- package/esm/date/datepicker/parts/HeadRow.js +1 -1
- package/esm/date/datepicker/parts/HeadRow.js.map +1 -1
- package/esm/date/datepicker/parts/Row.js +3 -3
- package/esm/date/datepicker/parts/Row.js.map +1 -1
- package/esm/date/monthpicker/MonthCaption.js +1 -1
- package/esm/date/monthpicker/MonthCaption.js.map +1 -1
- package/esm/date/parts/DateInput.js +1 -1
- package/esm/date/parts/DateInput.js.map +1 -1
- package/esm/date/utils/check-dates.js +1 -1
- package/esm/date/utils/check-dates.js.map +1 -1
- package/esm/date/utils/get-month-weeks.js.map +1 -1
- package/esm/date/utils/is-match.js +2 -2
- package/esm/date/utils/is-match.js.map +1 -1
- package/esm/date/utils/navigation.js.map +1 -1
- package/esm/date/utils/parse-date.js +1 -1
- package/esm/date/utils/parse-date.js.map +1 -1
- package/esm/dropdown/Dropdown.d.ts +4 -0
- package/esm/dropdown/Dropdown.js +10 -12
- package/esm/dropdown/Dropdown.js.map +1 -1
- package/esm/dropdown/Menu/Divider.js +1 -1
- package/esm/dropdown/Menu/Divider.js.map +1 -1
- package/esm/dropdown/Menu/GroupedList/GroupedHeading.js +1 -1
- package/esm/dropdown/Menu/GroupedList/GroupedHeading.js.map +1 -1
- package/esm/expansion-card/ExpansionCardHeader.js +1 -1
- package/esm/expansion-card/ExpansionCardHeader.js.map +1 -1
- package/esm/form/Fieldset/useFieldset.d.ts +1 -1
- package/esm/form/ReadOnlyIcon.js +1 -1
- package/esm/form/ReadOnlyIcon.js.map +1 -1
- package/esm/form/Select.js +1 -1
- package/esm/form/Select.js.map +1 -1
- package/esm/form/Switch.js.map +1 -1
- package/esm/form/TextField.js.map +1 -1
- package/esm/form/checkbox/useCheckbox.d.ts +1 -1
- package/esm/form/combobox/Combobox.d.ts +1 -1
- package/esm/form/combobox/Combobox.js +6 -6
- package/esm/form/combobox/Combobox.js.map +1 -1
- package/esm/form/combobox/ComboboxProvider.js +2 -2
- package/esm/form/combobox/ComboboxProvider.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js +4 -4
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.d.ts +1 -1
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js +4 -4
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
- package/esm/form/combobox/SelectedOptions/SelectedOptions.js +1 -1
- package/esm/form/combobox/SelectedOptions/SelectedOptions.js.map +1 -1
- package/esm/form/combobox/ToggleListButton.js +1 -1
- package/esm/form/combobox/ToggleListButton.js.map +1 -1
- package/esm/form/combobox/customOptionsContext.js +1 -1
- package/esm/form/combobox/customOptionsContext.js.map +1 -1
- package/esm/form/error-summary/ErrorSummary.js +3 -3
- package/esm/form/error-summary/ErrorSummary.js.map +1 -1
- package/esm/form/error-summary/ErrorSummaryItem.js +1 -1
- package/esm/form/error-summary/ErrorSummaryItem.js.map +1 -1
- package/esm/form/radio/useRadio.d.ts +1 -1
- package/esm/form/search/Search.js +1 -1
- package/esm/form/search/Search.js.map +1 -1
- package/esm/form/search/SearchButton.js +1 -1
- package/esm/form/search/SearchButton.js.map +1 -1
- package/esm/grid/Cell.js +1 -1
- package/esm/grid/Cell.js.map +1 -1
- package/esm/grid/Grid.js +1 -1
- package/esm/grid/Grid.js.map +1 -1
- package/esm/guide-panel/GuidePanel.js +1 -1
- package/esm/guide-panel/GuidePanel.js.map +1 -1
- package/esm/internal-header/InternalHeader.js.map +1 -1
- package/esm/internal-header/InternalHeaderButton.js +1 -1
- package/esm/internal-header/InternalHeaderButton.js.map +1 -1
- package/esm/internal-header/InternalHeaderTitle.js +1 -1
- package/esm/internal-header/InternalHeaderTitle.js.map +1 -1
- package/esm/internal-header/InternalHeaderUser.js +1 -1
- package/esm/internal-header/InternalHeaderUser.js.map +1 -1
- package/esm/internal-header/InternalHeaderUserButton.js +1 -1
- package/esm/internal-header/InternalHeaderUserButton.js.map +1 -1
- package/esm/layout/bleed/Bleed.js +1 -1
- package/esm/layout/bleed/Bleed.js.map +1 -1
- package/esm/layout/box/Box.d.ts +1 -1
- package/esm/layout/content-container/ContentContainer.js +1 -1
- package/esm/layout/content-container/ContentContainer.js.map +1 -1
- package/esm/layout/grid/HGrid.js +1 -1
- package/esm/layout/grid/HGrid.js.map +1 -1
- package/esm/layout/page/Page.d.ts +2 -2
- package/esm/layout/page/Page.js.map +1 -1
- package/esm/layout/page/parts/PageBlock.d.ts +6 -5
- package/esm/layout/page/parts/PageBlock.js +1 -1
- package/esm/layout/page/parts/PageBlock.js.map +1 -1
- package/esm/layout/responsive/Responsive.js.map +1 -1
- package/esm/layout/sidemal-test/AvatarPanel.js +1 -1
- package/esm/layout/sidemal-test/AvatarPanel.js.map +1 -1
- package/esm/layout/sidemal-test/Content.js +4 -4
- package/esm/layout/sidemal-test/Content.js.map +1 -1
- package/esm/layout/sidemal-test/Filter.js +1 -1
- package/esm/layout/sidemal-test/Filter.js.map +1 -1
- package/esm/layout/sidemal-test/Header.js +1 -1
- package/esm/layout/sidemal-test/Header.js.map +1 -1
- package/esm/layout/sidemal-test/Intro.js +2 -2
- package/esm/layout/sidemal-test/Intro.js.map +1 -1
- package/esm/layout/sidemal-test/content-box/ContentBox.js.map +1 -1
- package/esm/layout/stack/HStack.js.map +1 -1
- package/esm/layout/stack/Stack.js.map +1 -1
- package/esm/layout/stack/VStack.js.map +1 -1
- package/esm/layout/utilities/types.d.ts +2 -2
- package/esm/link-panel/LinkPanel.d.ts +2 -2
- package/esm/link-panel/LinkPanel.js +3 -3
- package/esm/link-panel/LinkPanel.js.map +1 -1
- package/esm/link-panel/LinkPanelDescription.js +1 -1
- package/esm/link-panel/LinkPanelDescription.js.map +1 -1
- package/esm/link-panel/LinkPanelTitle.js +1 -1
- package/esm/link-panel/LinkPanelTitle.js.map +1 -1
- package/esm/loader/Loader.js.map +1 -1
- package/esm/modal/ModalBody.js +1 -1
- package/esm/modal/ModalBody.js.map +1 -1
- package/esm/modal/ModalFooter.js +1 -1
- package/esm/modal/ModalFooter.js.map +1 -1
- package/esm/modal/ModalHeader.js +1 -1
- package/esm/modal/ModalHeader.js.map +1 -1
- package/esm/pagination/Pagination.js.map +1 -1
- package/esm/pagination/PaginationItem.js +1 -1
- package/esm/pagination/PaginationItem.js.map +1 -1
- package/esm/panel/Panel.js +1 -1
- package/esm/panel/Panel.js.map +1 -1
- package/esm/popover/Popover.js.map +1 -1
- package/esm/popover/PopoverContent.js +1 -1
- package/esm/popover/PopoverContent.js.map +1 -1
- package/esm/read-more/ReadMore.d.ts +4 -0
- package/esm/read-more/ReadMore.js +13 -11
- package/esm/read-more/ReadMore.js.map +1 -1
- package/esm/skeleton/Skeleton.js +1 -1
- package/esm/skeleton/Skeleton.js.map +1 -1
- package/esm/table/Body.js +1 -1
- package/esm/table/Body.js.map +1 -1
- package/esm/table/ColumnHeader.js +1 -1
- package/esm/table/ColumnHeader.js.map +1 -1
- package/esm/table/DataCell.js +1 -1
- package/esm/table/DataCell.js.map +1 -1
- package/esm/table/ExpandableRow.js +15 -14
- package/esm/table/ExpandableRow.js.map +1 -1
- package/esm/table/Header.js +1 -1
- package/esm/table/Header.js.map +1 -1
- package/esm/table/Row.js +1 -1
- package/esm/table/Row.js.map +1 -1
- package/esm/tabs/TabList.js +1 -1
- package/esm/tabs/TabList.js.map +1 -1
- package/esm/tabs/Tabs.js +1 -1
- package/esm/tabs/Tabs.js.map +1 -1
- package/esm/tag/Tag.js +1 -1
- package/esm/tag/Tag.js.map +1 -1
- package/esm/timeline/AxisLabels.js +1 -1
- package/esm/timeline/AxisLabels.js.map +1 -1
- package/esm/timeline/TimelineRow.js +2 -2
- package/esm/timeline/TimelineRow.js.map +1 -1
- package/esm/timeline/hooks/useTimelineRows.js +5 -3
- package/esm/timeline/hooks/useTimelineRows.js.map +1 -1
- package/esm/timeline/utils/timeline.js +1 -1
- package/esm/timeline/utils/timeline.js.map +1 -1
- package/esm/timeline/zoom/ZoomButton.js +1 -1
- package/esm/timeline/zoom/ZoomButton.js.map +1 -1
- package/esm/toggle-group/ToggleGroup.js +1 -1
- package/esm/toggle-group/ToggleGroup.js.map +1 -1
- package/esm/tooltip/Tooltip.d.ts +4 -0
- package/esm/tooltip/Tooltip.js +13 -8
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/esm/typography/BodyLong.js +1 -1
- package/esm/typography/BodyLong.js.map +1 -1
- package/esm/typography/ErrorMessage.js +1 -1
- package/esm/typography/ErrorMessage.js.map +1 -1
- package/esm/typography/Ingress.js +1 -1
- package/esm/typography/Ingress.js.map +1 -1
- package/esm/util/RandomIcon.js +1 -1
- package/esm/util/RandomIcon.js.map +1 -1
- package/esm/util/hooks/useCallbackRef.d.ts +7 -0
- package/esm/util/hooks/useCallbackRef.js +15 -0
- package/esm/util/hooks/useCallbackRef.js.map +1 -0
- package/esm/util/hooks/useControllableState.d.ts +9 -0
- package/esm/util/hooks/useControllableState.js +22 -0
- package/esm/util/hooks/useControllableState.js.map +1 -0
- package/esm/util/mergeRefs.js.map +1 -1
- package/package.json +3 -3
- package/src/accordion/Accordion.tsx +5 -5
- package/src/accordion/AccordionContent.tsx +3 -3
- package/src/accordion/AccordionHeader.tsx +3 -3
- package/src/accordion/AccordionItem.tsx +21 -21
- package/src/accordion/accordion.stories.tsx +8 -5
- package/src/alert/Alert.tsx +8 -8
- package/src/alert/alert.stories.tsx +7 -7
- package/src/button/Button.tsx +4 -4
- package/src/button/button.stories.tsx +1 -1
- package/src/chat/Bubble.tsx +4 -4
- package/src/chat/Chat.tsx +5 -5
- package/src/chat/chat.stories.tsx +1 -1
- package/src/chips/Chips.tsx +4 -4
- package/src/chips/Removable.tsx +4 -4
- package/src/chips/Toggle.tsx +3 -3
- package/src/chips/chips.stories.tsx +5 -5
- package/src/copybutton/CopyButton.tsx +6 -6
- package/src/copybutton/copy-button.stories.tsx +3 -3
- package/src/date/context/useSharedMonthContext.tsx +1 -1
- package/src/date/datepicker/DatePicker.tsx +2 -2
- package/src/date/datepicker/DatePickerStandalone.tsx +2 -2
- package/src/date/datepicker/datepicker.stories.tsx +2 -2
- package/src/date/datepicker/parts/Caption.tsx +2 -3
- package/src/date/datepicker/parts/DropdownCaption.tsx +2 -2
- package/src/date/datepicker/parts/HeadRow.tsx +1 -1
- package/src/date/datepicker/parts/Row.tsx +3 -3
- package/src/date/hooks/useDatepicker.tsx +7 -7
- package/src/date/hooks/useMonthPicker.tsx +7 -7
- package/src/date/hooks/useRangeDatepicker.test.tsx +2 -2
- package/src/date/hooks/useRangeDatepicker.tsx +28 -28
- package/src/date/monthpicker/MonthButton.tsx +1 -1
- package/src/date/monthpicker/MonthCaption.tsx +1 -1
- package/src/date/monthpicker/MonthPicker.tsx +3 -3
- package/src/date/monthpicker/MonthPickerStandalone.tsx +3 -3
- package/src/date/monthpicker/MonthSelector.tsx +1 -1
- package/src/date/parts/DateInput.tsx +6 -6
- package/src/date/utils/__tests__/check-dates.test.ts +3 -3
- package/src/date/utils/__tests__/format-dates.test.ts +7 -7
- package/src/date/utils/__tests__/get-initial-year.test.ts +14 -14
- package/src/date/utils/__tests__/get-month-weeks.test.ts +0 -1
- package/src/date/utils/__tests__/is-match.test.ts +4 -4
- package/src/date/utils/__tests__/parse-dates.test.ts +2 -2
- package/src/date/utils/check-dates.ts +2 -2
- package/src/date/utils/dates-disabled.ts +1 -1
- package/src/date/utils/format-date.ts +1 -1
- package/src/date/utils/get-dates.ts +1 -1
- package/src/date/utils/get-month-weeks.ts +6 -6
- package/src/date/utils/is-match.ts +2 -3
- package/src/date/utils/labels.ts +1 -1
- package/src/date/utils/navigation.ts +18 -18
- package/src/date/utils/parse-date.ts +8 -8
- package/src/dropdown/Dropdown.tsx +14 -11
- package/src/dropdown/Menu/Divider.tsx +1 -1
- package/src/dropdown/Menu/GroupedList/GroupedHeading.tsx +2 -2
- package/src/dropdown/Menu/GroupedList/GroupedItem.tsx +1 -1
- package/src/dropdown/Menu/GroupedList/index.tsx +1 -1
- package/src/dropdown/Menu/List/Item.tsx +1 -1
- package/src/dropdown/Menu/index.tsx +1 -1
- package/src/dropdown/dropdown.stories.tsx +1 -1
- package/src/expansion-card/ExpansionCard.tsx +3 -3
- package/src/expansion-card/ExpansionCardContent.tsx +1 -1
- package/src/expansion-card/ExpansionCardDescription.tsx +1 -1
- package/src/expansion-card/ExpansionCardHeader.tsx +2 -2
- package/src/expansion-card/ExpansionCardTitle.tsx +2 -2
- package/src/expansion-card/expansion-card.stories.tsx +1 -1
- package/src/form/ConfirmationPanel.test.tsx +1 -1
- package/src/form/ConfirmationPanel.tsx +2 -2
- package/src/form/Fieldset/Fieldset.tsx +2 -2
- package/src/form/ReadOnlyIcon.tsx +1 -1
- package/src/form/Select.tsx +6 -6
- package/src/form/Switch.tsx +4 -4
- package/src/form/TextField.tsx +4 -4
- package/src/form/Textarea.tsx +4 -4
- package/src/form/checkbox/Checkbox.test.tsx +8 -8
- package/src/form/checkbox/Checkbox.tsx +3 -3
- package/src/form/checkbox/CheckboxGroup.tsx +4 -4
- package/src/form/checkbox/useCheckbox.ts +3 -3
- package/src/form/combobox/Combobox.tsx +8 -8
- package/src/form/combobox/ComboboxProvider.tsx +3 -3
- package/src/form/combobox/ComboboxWrapper.tsx +1 -1
- package/src/form/combobox/FilteredOptions/FilteredOptions.tsx +6 -6
- package/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx +18 -18
- package/src/form/combobox/FilteredOptions/useVirtualFocus.ts +5 -5
- package/src/form/combobox/Input/Input.tsx +6 -6
- package/src/form/combobox/Input/inputContext.tsx +6 -6
- package/src/form/combobox/SelectedOptions/SelectedOptions.tsx +1 -1
- package/src/form/combobox/SelectedOptions/selectedOptionsContext.tsx +9 -9
- package/src/form/combobox/ToggleListButton.tsx +1 -2
- package/src/form/combobox/combobox.stories.tsx +8 -8
- package/src/form/combobox/combobox.test.tsx +14 -12
- package/src/form/combobox/customOptionsContext.tsx +6 -6
- package/src/form/combobox/types.ts +2 -2
- package/src/form/error-summary/ErrorSummary.tsx +6 -6
- package/src/form/error-summary/ErrorSummaryItem.tsx +2 -2
- package/src/form/error-summary/error-summary.stories.tsx +2 -1
- package/src/form/radio/Radio.test.tsx +1 -1
- package/src/form/radio/Radio.tsx +1 -1
- package/src/form/radio/RadioGroup.tsx +3 -3
- package/src/form/radio/useRadio.ts +1 -1
- package/src/form/search/Search.tsx +6 -6
- package/src/form/search/SearchButton.tsx +2 -2
- package/src/form/search/search.stories.tsx +1 -1
- package/src/form/stories/fieldset.stories.tsx +3 -2
- package/src/form/stories/select.stories.tsx +2 -1
- package/src/form/stories/text-field.stories.tsx +2 -1
- package/src/form/useFormField.ts +3 -3
- package/src/grid/Cell.tsx +3 -3
- package/src/grid/Grid.tsx +2 -2
- package/src/grid/grid.stories.tsx +1 -1
- package/src/guide-panel/GuidePanel.tsx +2 -2
- package/src/guide-panel/guidepanel.stories.tsx +1 -1
- package/src/help-text/HelpText.tsx +2 -2
- package/src/internal-header/InternalHeader.tsx +1 -1
- package/src/internal-header/InternalHeaderButton.tsx +1 -1
- package/src/internal-header/InternalHeaderTitle.tsx +1 -1
- package/src/internal-header/InternalHeaderUser.tsx +1 -1
- package/src/internal-header/InternalHeaderUserButton.tsx +1 -1
- package/src/internal-header/header.stories.tsx +3 -3
- package/src/layout/bleed/Bleed.tsx +7 -7
- package/src/layout/box/Box.stories.tsx +4 -4
- package/src/layout/box/Box.tsx +7 -7
- package/src/layout/content-container/ContentContainer.tsx +1 -1
- package/src/layout/grid/HGrid.tsx +4 -4
- package/src/layout/page/Page.stories.tsx +1 -1
- package/src/layout/page/Page.tsx +4 -4
- package/src/layout/page/parts/PageBlock.tsx +8 -7
- package/src/layout/responsive/Responsive.tsx +6 -6
- package/src/layout/responsive/hide.stories.tsx +1 -1
- package/src/layout/responsive/show.stories.tsx +1 -1
- package/src/layout/sidemal-test/AvatarPanel.tsx +1 -1
- package/src/layout/sidemal-test/Content.tsx +4 -4
- package/src/layout/sidemal-test/Filter.tsx +1 -1
- package/src/layout/sidemal-test/Header.tsx +1 -1
- package/src/layout/sidemal-test/Intro.tsx +2 -2
- package/src/layout/sidemal-test/content-box/ContentBox.tsx +6 -6
- package/src/layout/sidemal-test/navno-sidemal.stories.tsx +1 -1
- package/src/layout/stack/HStack.tsx +1 -1
- package/src/layout/stack/Stack.tsx +3 -3
- package/src/layout/stack/VStack.tsx +1 -1
- package/src/layout/stack/stack.stories.tsx +2 -2
- package/src/layout/utilities/css.ts +6 -6
- package/src/layout/utilities/types.ts +2 -2
- package/src/link/Link.tsx +2 -2
- package/src/link/link.stories.tsx +1 -1
- package/src/link-panel/LinkPanel.tsx +6 -7
- package/src/link-panel/LinkPanelDescription.tsx +1 -1
- package/src/link-panel/LinkPanelTitle.tsx +2 -2
- package/src/list/List.tsx +2 -2
- package/src/list/ListItem.tsx +2 -2
- package/src/list/list.stories.tsx +2 -2
- package/src/loader/Loader.tsx +4 -4
- package/src/loader/loader.stories.tsx +1 -0
- package/src/modal/Modal.test.tsx +4 -4
- package/src/modal/Modal.tsx +2 -2
- package/src/modal/ModalBody.tsx +2 -2
- package/src/modal/ModalFooter.tsx +2 -2
- package/src/modal/ModalHeader.tsx +2 -2
- package/src/modal/ModalUtils.ts +2 -2
- package/src/modal/dialog-polyfill.ts +16 -16
- package/src/pagination/Pagination.tsx +5 -6
- package/src/pagination/PaginationItem.tsx +3 -3
- package/src/pagination/steps.test.ts +8 -8
- package/src/panel/Panel.tsx +3 -3
- package/src/panel/panel.stories.tsx +2 -1
- package/src/popover/Popover.test.tsx +7 -7
- package/src/popover/Popover.tsx +8 -8
- package/src/popover/PopoverContent.tsx +2 -2
- package/src/provider/Provider.tsx +1 -1
- package/src/read-more/ReadMore.tsx +19 -13
- package/src/read-more/readmore.stories.tsx +4 -0
- package/src/skeleton/Skeleton.tsx +4 -4
- package/src/stepper/Step.tsx +2 -2
- package/src/stepper/Stepper.tsx +3 -3
- package/src/table/Body.tsx +1 -1
- package/src/table/ColumnHeader.tsx +2 -2
- package/src/table/DataCell.tsx +2 -2
- package/src/table/ExpandableRow.tsx +19 -17
- package/src/table/Header.tsx +1 -1
- package/src/table/HeaderCell.tsx +1 -1
- package/src/table/Row.tsx +2 -2
- package/src/table/Table.tsx +2 -2
- package/src/table/stories/table-async.stories.tsx +4 -4
- package/src/table/stories/table.stories.tsx +1 -1
- package/src/tabs/Tab.tsx +3 -3
- package/src/tabs/TabList.tsx +4 -4
- package/src/tabs/TabPanel.tsx +1 -1
- package/src/tabs/Tabs.stories.tsx +1 -1
- package/src/tabs/Tabs.tsx +4 -4
- package/src/tag/Tag.tsx +3 -3
- package/src/tag/tag.stories.tsx +1 -1
- package/src/timeline/AxisLabels.tsx +9 -9
- package/src/timeline/Pin.tsx +2 -2
- package/src/timeline/Timeline.tsx +7 -7
- package/src/timeline/TimelineRow.tsx +5 -5
- package/src/timeline/hooks/useTimelineContext.tsx +1 -1
- package/src/timeline/hooks/useTimelineRows.ts +18 -19
- package/src/timeline/period/ClickablePeriod.tsx +4 -4
- package/src/timeline/period/NonClickablePeriod.tsx +1 -1
- package/src/timeline/period/index.tsx +1 -1
- package/src/timeline/timeline.stories.tsx +2 -2
- package/src/timeline/utils/calc.ts +2 -2
- package/src/timeline/utils/filter.ts +2 -2
- package/src/timeline/utils/period.ts +2 -2
- package/src/timeline/utils/timeline.ts +1 -1
- package/src/timeline/zoom/ZoomButton.tsx +3 -3
- package/src/timeline/zoom/index.tsx +1 -1
- package/src/toggle-group/ToggleGroup.stories.tsx +2 -2
- package/src/toggle-group/ToggleGroup.tsx +5 -5
- package/src/toggle-group/ToggleItem.tsx +1 -1
- package/src/toggle-group/context.ts +1 -1
- package/src/tooltip/Tooltip.test.tsx +10 -10
- package/src/tooltip/Tooltip.tsx +20 -11
- package/src/tooltip/tooltip.stories.tsx +1 -1
- package/src/typography/BodyLong.tsx +4 -4
- package/src/typography/BodyShort.tsx +3 -3
- package/src/typography/Detail.tsx +3 -3
- package/src/typography/ErrorMessage.tsx +3 -3
- package/src/typography/Heading.tsx +3 -3
- package/src/typography/Ingress.tsx +1 -1
- package/src/typography/Label.tsx +3 -3
- package/src/typography/stories/heading.stories.tsx +1 -2
- package/src/util/AnimateHeight.tsx +1 -1
- package/src/util/OverridableComponent.ts +1 -1
- package/src/util/RandomIcon.tsx +1 -1
- package/src/util/Slot.tsx +3 -3
- package/src/util/TextareaAutoSize.tsx +4 -4
- package/src/util/__tests__/Slot.test.tsx +11 -11
- package/src/util/hooks/useCallbackRef.ts +20 -0
- package/src/util/hooks/useControllableState.ts +40 -0
- package/src/util/mergeRefs.tsx +2 -1
- package/src/util/omit.ts +1 -1
- package/src/util/useEventListener.ts +1 -1
- package/src/util/useMedia.ts +1 -1
|
@@ -16,7 +16,7 @@ test("checkbox group chains onChange calls", async () => {
|
|
|
16
16
|
<Checkbox onChange={onChange} value={value}>
|
|
17
17
|
{label}
|
|
18
18
|
</Checkbox>
|
|
19
|
-
</CheckboxGroup
|
|
19
|
+
</CheckboxGroup>,
|
|
20
20
|
);
|
|
21
21
|
|
|
22
22
|
fireEvent.click(screen.getByLabelText(label));
|
|
@@ -42,11 +42,11 @@ describe("Checkbox handles controlled-state correctly", () => {
|
|
|
42
42
|
fireEvent.click(screen.getByLabelText("label2"));
|
|
43
43
|
|
|
44
44
|
expect((screen.getByLabelText("label1") as HTMLInputElement).checked).toBe(
|
|
45
|
-
true
|
|
45
|
+
true,
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
expect((screen.getByLabelText("label2") as HTMLInputElement).checked).toBe(
|
|
49
|
-
true
|
|
49
|
+
true,
|
|
50
50
|
);
|
|
51
51
|
});
|
|
52
52
|
|
|
@@ -57,7 +57,7 @@ describe("Checkbox handles controlled-state correctly", () => {
|
|
|
57
57
|
<CheckboxComponent
|
|
58
58
|
onChange={onGroupChange}
|
|
59
59
|
value={["value1", "value2"]}
|
|
60
|
-
|
|
60
|
+
/>,
|
|
61
61
|
);
|
|
62
62
|
|
|
63
63
|
fireEvent.click(screen.getByLabelText("label1"));
|
|
@@ -71,19 +71,19 @@ describe("Checkbox handles controlled-state correctly", () => {
|
|
|
71
71
|
const { rerender } = render(<CheckboxComponent value={[]} />);
|
|
72
72
|
|
|
73
73
|
expect((screen.getByLabelText("label1") as HTMLInputElement).checked).toBe(
|
|
74
|
-
false
|
|
74
|
+
false,
|
|
75
75
|
);
|
|
76
76
|
expect((screen.getByLabelText("label2") as HTMLInputElement).checked).toBe(
|
|
77
|
-
false
|
|
77
|
+
false,
|
|
78
78
|
);
|
|
79
79
|
|
|
80
80
|
rerender(<CheckboxComponent value={["value1", "value2"]} />);
|
|
81
81
|
|
|
82
82
|
expect((screen.getByLabelText("label1") as HTMLInputElement).checked).toBe(
|
|
83
|
-
true
|
|
83
|
+
true,
|
|
84
84
|
);
|
|
85
85
|
expect((screen.getByLabelText("label2") as HTMLInputElement).checked).toBe(
|
|
86
|
-
true
|
|
86
|
+
true,
|
|
87
87
|
);
|
|
88
88
|
});
|
|
89
89
|
});
|
|
@@ -23,7 +23,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
|
|
|
23
23
|
"navds-checkbox--error": hasError,
|
|
24
24
|
"navds-checkbox--disabled": inputProps.disabled,
|
|
25
25
|
"navds-checkbox--readonly": readOnly,
|
|
26
|
-
}
|
|
26
|
+
},
|
|
27
27
|
)}
|
|
28
28
|
>
|
|
29
29
|
<input
|
|
@@ -57,7 +57,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
|
|
|
57
57
|
!!props["aria-labelledby"] && props["aria-labelledby"],
|
|
58
58
|
{
|
|
59
59
|
[descriptionId]: props.description,
|
|
60
|
-
}
|
|
60
|
+
},
|
|
61
61
|
)}
|
|
62
62
|
/>
|
|
63
63
|
<label htmlFor={inputProps.id} className="navds-checkbox__label">
|
|
@@ -110,7 +110,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
|
|
|
110
110
|
</label>
|
|
111
111
|
</div>
|
|
112
112
|
);
|
|
113
|
-
}
|
|
113
|
+
},
|
|
114
114
|
);
|
|
115
115
|
|
|
116
116
|
export default Checkbox;
|
|
@@ -9,7 +9,7 @@ export interface CheckboxGroupState {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const CheckboxGroupContext = createContext<CheckboxGroupState | null>(
|
|
12
|
-
null
|
|
12
|
+
null,
|
|
13
13
|
);
|
|
14
14
|
|
|
15
15
|
export interface CheckboxGroupProps
|
|
@@ -56,7 +56,7 @@ export const CheckboxGroup = forwardRef<
|
|
|
56
56
|
>(
|
|
57
57
|
(
|
|
58
58
|
{ value, defaultValue, onChange = () => {}, children, className, ...rest },
|
|
59
|
-
ref
|
|
59
|
+
ref,
|
|
60
60
|
) => {
|
|
61
61
|
const fieldset = useContext(FieldsetContext);
|
|
62
62
|
|
|
@@ -79,7 +79,7 @@ export const CheckboxGroup = forwardRef<
|
|
|
79
79
|
className={cl(
|
|
80
80
|
className,
|
|
81
81
|
"navds-checkbox-group",
|
|
82
|
-
`navds-checkbox-group--${rest.size ?? fieldset?.size ?? "medium"}
|
|
82
|
+
`navds-checkbox-group--${rest.size ?? fieldset?.size ?? "medium"}`,
|
|
83
83
|
)}
|
|
84
84
|
nativeReadOnly={false}
|
|
85
85
|
>
|
|
@@ -94,7 +94,7 @@ export const CheckboxGroup = forwardRef<
|
|
|
94
94
|
</CheckboxGroupContext.Provider>
|
|
95
95
|
</Fieldset>
|
|
96
96
|
);
|
|
97
|
-
}
|
|
97
|
+
},
|
|
98
98
|
);
|
|
99
99
|
|
|
100
100
|
export default CheckboxGroup;
|
|
@@ -12,18 +12,18 @@ const useCheckbox = (props: CheckboxProps) => {
|
|
|
12
12
|
|
|
13
13
|
const { inputProps, readOnly, ...rest } = useFormField(
|
|
14
14
|
omit(props, ["description", "children"]),
|
|
15
|
-
"checkbox"
|
|
15
|
+
"checkbox",
|
|
16
16
|
);
|
|
17
17
|
|
|
18
18
|
if (checkboxGroup) {
|
|
19
19
|
if (props.checked) {
|
|
20
20
|
console.warn(
|
|
21
|
-
"`checked` is unsupported on <Checkbox> elements within a <CheckboxGroup>. Please set a `value` or `defaultValue` on <CheckboxGroup> instead."
|
|
21
|
+
"`checked` is unsupported on <Checkbox> elements within a <CheckboxGroup>. Please set a `value` or `defaultValue` on <CheckboxGroup> instead.",
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
24
|
if (props.value === undefined) {
|
|
25
25
|
console.warn(
|
|
26
|
-
"A <Checkbox> element within a <CheckboxGroup> requires a `value` property."
|
|
26
|
+
"A <Checkbox> element within a <CheckboxGroup> requires a `value` property.",
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import cl from "clsx";
|
|
2
2
|
import React, { forwardRef, useMemo, useRef } from "react";
|
|
3
|
+
import { BodyShort, ErrorMessage, Label } from "../../typography";
|
|
4
|
+
import { mergeRefs } from "../../util";
|
|
3
5
|
import ClearButton from "./ClearButton";
|
|
6
|
+
import ComboboxWrapper from "./ComboboxWrapper";
|
|
4
7
|
import FilteredOptions from "./FilteredOptions/FilteredOptions";
|
|
5
8
|
import { useFilteredOptionsContext } from "./FilteredOptions/filteredOptionsContext";
|
|
9
|
+
import Input from "./Input/Input";
|
|
10
|
+
import { useInputContext } from "./Input/inputContext";
|
|
6
11
|
import SelectedOptions from "./SelectedOptions/SelectedOptions";
|
|
12
|
+
import { useSelectedOptionsContext } from "./SelectedOptions/selectedOptionsContext";
|
|
7
13
|
import ToggleListButton from "./ToggleListButton";
|
|
8
14
|
import { ComboboxProps } from "./types";
|
|
9
|
-
import { useSelectedOptionsContext } from "./SelectedOptions/selectedOptionsContext";
|
|
10
|
-
import ComboboxWrapper from "./ComboboxWrapper";
|
|
11
|
-
import { useInputContext } from "./Input/inputContext";
|
|
12
|
-
import Input from "./Input/Input";
|
|
13
|
-
import { mergeRefs } from "../../util";
|
|
14
|
-
import { BodyShort, ErrorMessage, Label } from "../../typography";
|
|
15
15
|
|
|
16
16
|
export const Combobox = forwardRef<
|
|
17
17
|
HTMLInputElement,
|
|
@@ -52,7 +52,7 @@ export const Combobox = forwardRef<
|
|
|
52
52
|
|
|
53
53
|
const mergedInputRef = useMemo(
|
|
54
54
|
() => mergeRefs([inputRef, ref]),
|
|
55
|
-
[inputRef, ref]
|
|
55
|
+
[inputRef, ref],
|
|
56
56
|
);
|
|
57
57
|
|
|
58
58
|
return (
|
|
@@ -93,7 +93,7 @@ export const Combobox = forwardRef<
|
|
|
93
93
|
{
|
|
94
94
|
"navds-combobox__wrapper-inner--virtually-unfocused":
|
|
95
95
|
activeDecendantId !== null,
|
|
96
|
-
}
|
|
96
|
+
},
|
|
97
97
|
)}
|
|
98
98
|
onClick={focusInput}
|
|
99
99
|
>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { forwardRef } from "react";
|
|
2
2
|
import Combobox from "./Combobox";
|
|
3
3
|
import { FilteredOptionsProvider } from "./FilteredOptions/filteredOptionsContext";
|
|
4
|
-
import { CustomOptionsProvider } from "./customOptionsContext";
|
|
5
|
-
import { SelectedOptionsProvider } from "./SelectedOptions/selectedOptionsContext";
|
|
6
4
|
import { InputContextProvider } from "./Input/inputContext";
|
|
5
|
+
import { SelectedOptionsProvider } from "./SelectedOptions/selectedOptionsContext";
|
|
6
|
+
import { CustomOptionsProvider } from "./customOptionsContext";
|
|
7
7
|
import { ComboboxProps } from "./types";
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -92,7 +92,7 @@ const ComboboxProvider = forwardRef<HTMLInputElement, ComboboxProps>(
|
|
|
92
92
|
</CustomOptionsProvider>
|
|
93
93
|
</InputContextProvider>
|
|
94
94
|
);
|
|
95
|
-
}
|
|
95
|
+
},
|
|
96
96
|
);
|
|
97
97
|
|
|
98
98
|
export default ComboboxProvider;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import cl from "clsx";
|
|
2
|
+
import React from "react";
|
|
3
3
|
import { CheckmarkIcon, PlusIcon } from "@navikt/aksel-icons";
|
|
4
|
-
import { useFilteredOptionsContext } from "./filteredOptionsContext";
|
|
5
|
-
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
|
|
6
|
-
import { useInputContext } from "../Input/inputContext";
|
|
7
4
|
import { Loader } from "../../../loader";
|
|
8
5
|
import { BodyShort, Label } from "../../../typography";
|
|
6
|
+
import { useInputContext } from "../Input/inputContext";
|
|
7
|
+
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
|
|
9
8
|
import filteredOptionsUtil from "./filtered-options-util";
|
|
9
|
+
import { useFilteredOptionsContext } from "./filteredOptionsContext";
|
|
10
10
|
|
|
11
11
|
const FilteredOptions = () => {
|
|
12
12
|
const {
|
|
@@ -60,7 +60,7 @@ const FilteredOptions = () => {
|
|
|
60
60
|
activeDecendantId !== filteredOptionsUtil.getAddNewOptionId(id)
|
|
61
61
|
) {
|
|
62
62
|
virtualFocus.moveFocusToElement(
|
|
63
|
-
filteredOptionsUtil.getAddNewOptionId(id)
|
|
63
|
+
filteredOptionsUtil.getAddNewOptionId(id),
|
|
64
64
|
);
|
|
65
65
|
setIsMouseLastUsedInputDevice(true);
|
|
66
66
|
}
|
|
@@ -114,7 +114,7 @@ const FilteredOptions = () => {
|
|
|
114
114
|
activeDecendantId !== filteredOptionsUtil.getOptionId(id, option)
|
|
115
115
|
) {
|
|
116
116
|
virtualFocus.moveFocusToElement(
|
|
117
|
-
filteredOptionsUtil.getOptionId(id, option)
|
|
117
|
+
filteredOptionsUtil.getOptionId(id, option),
|
|
118
118
|
);
|
|
119
119
|
setIsMouseLastUsedInputDevice(true);
|
|
120
120
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
import cl from "clsx";
|
|
1
2
|
import React, {
|
|
2
|
-
|
|
3
|
-
useMemo,
|
|
3
|
+
SetStateAction,
|
|
4
4
|
createContext,
|
|
5
|
-
useContext,
|
|
6
5
|
useCallback,
|
|
7
|
-
|
|
6
|
+
useContext,
|
|
7
|
+
useMemo,
|
|
8
|
+
useState,
|
|
8
9
|
} from "react";
|
|
9
|
-
import cl from "clsx";
|
|
10
|
-
import { useCustomOptionsContext } from "../customOptionsContext";
|
|
11
|
-
import { useInputContext } from "../Input/inputContext";
|
|
12
|
-
import usePrevious from "../../../util/usePrevious";
|
|
13
10
|
import { useClientLayoutEffect } from "../../../util";
|
|
11
|
+
import usePrevious from "../../../util/usePrevious";
|
|
12
|
+
import { useInputContext } from "../Input/inputContext";
|
|
13
|
+
import { useCustomOptionsContext } from "../customOptionsContext";
|
|
14
|
+
import { ComboboxProps } from "../types";
|
|
14
15
|
import filteredOptionsUtils from "./filtered-options-util";
|
|
15
16
|
import useVirtualFocus, { VirtualFocusType } from "./useVirtualFocus";
|
|
16
|
-
import { ComboboxProps } from "../types";
|
|
17
17
|
|
|
18
18
|
type FilteredOptionsProps = {
|
|
19
19
|
children: any;
|
|
@@ -46,7 +46,7 @@ type FilteredOptionsContextType = {
|
|
|
46
46
|
virtualFocus: VirtualFocusType;
|
|
47
47
|
};
|
|
48
48
|
const FilteredOptionsContext = createContext<FilteredOptionsContextType>(
|
|
49
|
-
{} as FilteredOptionsContextType
|
|
49
|
+
{} as FilteredOptionsContextType,
|
|
50
50
|
);
|
|
51
51
|
|
|
52
52
|
export const FilteredOptionsProvider = ({
|
|
@@ -99,9 +99,9 @@ export const FilteredOptionsProvider = ({
|
|
|
99
99
|
[filteredOptionsUtils.getAddNewOptionId(id)]: allowNewValues
|
|
100
100
|
? value
|
|
101
101
|
: undefined,
|
|
102
|
-
}
|
|
102
|
+
},
|
|
103
103
|
),
|
|
104
|
-
[allowNewValues, id, options, value]
|
|
104
|
+
[allowNewValues, id, options, value],
|
|
105
105
|
);
|
|
106
106
|
|
|
107
107
|
useClientLayoutEffect(() => {
|
|
@@ -112,7 +112,7 @@ export const FilteredOptionsProvider = ({
|
|
|
112
112
|
filteredOptions.length > 0
|
|
113
113
|
) {
|
|
114
114
|
setValue(
|
|
115
|
-
`${searchTerm}${filteredOptions[0].substring(searchTerm.length)}
|
|
115
|
+
`${searchTerm}${filteredOptions[0].substring(searchTerm.length)}`,
|
|
116
116
|
);
|
|
117
117
|
setSearchTerm(searchTerm);
|
|
118
118
|
}
|
|
@@ -134,14 +134,14 @@ export const FilteredOptionsProvider = ({
|
|
|
134
134
|
virtualFocus.moveFocusToTop();
|
|
135
135
|
setInternalListOpen((oldState) => newState ?? !oldState);
|
|
136
136
|
},
|
|
137
|
-
[virtualFocus]
|
|
137
|
+
[virtualFocus],
|
|
138
138
|
);
|
|
139
139
|
|
|
140
140
|
const isValueNew = useMemo(
|
|
141
141
|
() =>
|
|
142
142
|
Boolean(value) &&
|
|
143
143
|
!filteredOptionsMap[filteredOptionsUtils.getOptionId(id, value)],
|
|
144
|
-
[filteredOptionsMap, id, value]
|
|
144
|
+
[filteredOptionsMap, id, value],
|
|
145
145
|
);
|
|
146
146
|
|
|
147
147
|
const ariaDescribedBy = useMemo(() => {
|
|
@@ -169,12 +169,12 @@ export const FilteredOptionsProvider = ({
|
|
|
169
169
|
const currentOption = useMemo(
|
|
170
170
|
() =>
|
|
171
171
|
filteredOptionsMap[virtualFocus.activeElement?.getAttribute("id") || -1],
|
|
172
|
-
[filteredOptionsMap, virtualFocus]
|
|
172
|
+
[filteredOptionsMap, virtualFocus],
|
|
173
173
|
);
|
|
174
174
|
|
|
175
175
|
const activeDecendantId = useMemo(
|
|
176
176
|
() => virtualFocus.activeElement?.getAttribute("id") || undefined,
|
|
177
|
-
[virtualFocus.activeElement]
|
|
177
|
+
[virtualFocus.activeElement],
|
|
178
178
|
);
|
|
179
179
|
|
|
180
180
|
const filteredOptionsState = {
|
|
@@ -205,7 +205,7 @@ export const useFilteredOptionsContext = () => {
|
|
|
205
205
|
const context = useContext(FilteredOptionsContext);
|
|
206
206
|
if (!context) {
|
|
207
207
|
throw new Error(
|
|
208
|
-
"useFilteredOptionsContext must be used within a FilteredOptionsProvider"
|
|
208
|
+
"useFilteredOptionsContext must be used within a FilteredOptionsProvider",
|
|
209
209
|
);
|
|
210
210
|
}
|
|
211
211
|
return context;
|
|
@@ -14,7 +14,7 @@ export type VirtualFocusType = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
const useVirtualFocus = (
|
|
17
|
-
containerRef: HTMLElement | null
|
|
17
|
+
containerRef: HTMLElement | null,
|
|
18
18
|
): VirtualFocusType => {
|
|
19
19
|
const [index, setIndex] = useState(-1);
|
|
20
20
|
|
|
@@ -22,7 +22,7 @@ const useVirtualFocus = (
|
|
|
22
22
|
? Array.prototype.slice.call(containerRef?.children)
|
|
23
23
|
: [];
|
|
24
24
|
const elementsAbleToReceiveFocus = listOfAllChildren.filter(
|
|
25
|
-
(child) => child.getAttribute("data-no-focus") !== "true"
|
|
25
|
+
(child) => child.getAttribute("data-no-focus") !== "true",
|
|
26
26
|
);
|
|
27
27
|
|
|
28
28
|
const activeElement = elementsAbleToReceiveFocus[index];
|
|
@@ -34,7 +34,7 @@ const useVirtualFocus = (
|
|
|
34
34
|
const scrollToOption = (newIndex: number) => {
|
|
35
35
|
const indexOfElementToScrollTo = Math.min(
|
|
36
36
|
Math.max(newIndex, 0),
|
|
37
|
-
containerRef?.children.length || 0
|
|
37
|
+
containerRef?.children.length || 0,
|
|
38
38
|
);
|
|
39
39
|
if (containerRef?.children[indexOfElementToScrollTo]) {
|
|
40
40
|
const child = containerRef.children[indexOfElementToScrollTo];
|
|
@@ -53,14 +53,14 @@ const useVirtualFocus = (
|
|
|
53
53
|
const moveFocusUp = () => _moveFocusAndScrollTo(Math.max(index - 1, -1));
|
|
54
54
|
const moveFocusDown = () =>
|
|
55
55
|
_moveFocusAndScrollTo(
|
|
56
|
-
Math.min(index + 1, elementsAbleToReceiveFocus.length - 1)
|
|
56
|
+
Math.min(index + 1, elementsAbleToReceiveFocus.length - 1),
|
|
57
57
|
);
|
|
58
58
|
const moveFocusToTop = () => _moveFocusAndScrollTo(-1);
|
|
59
59
|
const moveFocusToBottom = () =>
|
|
60
60
|
_moveFocusAndScrollTo(elementsAbleToReceiveFocus.length - 1);
|
|
61
61
|
const moveFocusToElement = (id: string) => {
|
|
62
62
|
const thisElement = elementsAbleToReceiveFocus.find(
|
|
63
|
-
(_element) => _element.getAttribute("id") === id
|
|
63
|
+
(_element) => _element.getAttribute("id") === id,
|
|
64
64
|
);
|
|
65
65
|
const indexOfElement = thisElement
|
|
66
66
|
? elementsAbleToReceiveFocus.indexOf(thisElement)
|
|
@@ -45,7 +45,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
|
|
|
45
45
|
(event: React.KeyboardEvent) => {
|
|
46
46
|
const isTextInSelectedOptions = (text: string) => {
|
|
47
47
|
return selectedOptions.find(
|
|
48
|
-
(item) => item.toLocaleLowerCase() === text.toLocaleLowerCase()
|
|
48
|
+
(item) => item.toLocaleLowerCase() === text.toLocaleLowerCase(),
|
|
49
49
|
);
|
|
50
50
|
};
|
|
51
51
|
|
|
@@ -86,7 +86,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
|
|
|
86
86
|
toggleIsListOpen,
|
|
87
87
|
toggleOption,
|
|
88
88
|
value,
|
|
89
|
-
]
|
|
89
|
+
],
|
|
90
90
|
);
|
|
91
91
|
|
|
92
92
|
const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
@@ -151,7 +151,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
|
|
|
151
151
|
setIsMouseLastUsedInputDevice,
|
|
152
152
|
toggleIsListOpen,
|
|
153
153
|
virtualFocus,
|
|
154
|
-
]
|
|
154
|
+
],
|
|
155
155
|
);
|
|
156
156
|
|
|
157
157
|
const onChangeHandler = useCallback(
|
|
@@ -165,7 +165,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
|
|
|
165
165
|
virtualFocus.moveFocusToTop();
|
|
166
166
|
onChange(event);
|
|
167
167
|
},
|
|
168
|
-
[filteredOptions.length, virtualFocus, onChange, toggleIsListOpen]
|
|
168
|
+
[filteredOptions.length, virtualFocus, onChange, toggleIsListOpen],
|
|
169
169
|
);
|
|
170
170
|
|
|
171
171
|
return (
|
|
@@ -190,11 +190,11 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
|
|
|
190
190
|
inputClassName,
|
|
191
191
|
"navds-combobox__input",
|
|
192
192
|
"navds-body-short",
|
|
193
|
-
`navds-body-short--${size}
|
|
193
|
+
`navds-body-short--${size}`,
|
|
194
194
|
)}
|
|
195
195
|
/>
|
|
196
196
|
);
|
|
197
|
-
}
|
|
197
|
+
},
|
|
198
198
|
);
|
|
199
199
|
|
|
200
200
|
export default Input;
|
|
@@ -49,14 +49,14 @@ export const InputContextProvider = ({ children, value: props }) => {
|
|
|
49
49
|
id: externalId,
|
|
50
50
|
size,
|
|
51
51
|
},
|
|
52
|
-
"comboboxfield"
|
|
52
|
+
"comboboxfield",
|
|
53
53
|
);
|
|
54
54
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
55
55
|
const [internalValue, setInternalValue] = useState<string>(defaultValue);
|
|
56
56
|
|
|
57
57
|
const value = useMemo(
|
|
58
58
|
() => String(externalValue ?? internalValue),
|
|
59
|
-
[externalValue, internalValue]
|
|
59
|
+
[externalValue, internalValue],
|
|
60
60
|
);
|
|
61
61
|
|
|
62
62
|
const [searchTerm, setSearchTerm] = useState(value);
|
|
@@ -68,14 +68,14 @@ export const InputContextProvider = ({ children, value: props }) => {
|
|
|
68
68
|
externalOnChange?.(event);
|
|
69
69
|
setSearchTerm(newValue);
|
|
70
70
|
},
|
|
71
|
-
[externalValue, externalOnChange]
|
|
71
|
+
[externalValue, externalOnChange],
|
|
72
72
|
);
|
|
73
73
|
|
|
74
74
|
const setValue = useCallback(
|
|
75
75
|
(text) => {
|
|
76
76
|
setInternalValue(text);
|
|
77
77
|
},
|
|
78
|
-
[setInternalValue]
|
|
78
|
+
[setInternalValue],
|
|
79
79
|
);
|
|
80
80
|
|
|
81
81
|
const clearInput = useCallback(
|
|
@@ -85,7 +85,7 @@ export const InputContextProvider = ({ children, value: props }) => {
|
|
|
85
85
|
setValue("");
|
|
86
86
|
setSearchTerm("");
|
|
87
87
|
},
|
|
88
|
-
[externalOnChange, onClear, setValue]
|
|
88
|
+
[externalOnChange, onClear, setValue],
|
|
89
89
|
);
|
|
90
90
|
|
|
91
91
|
const focusInput = useCallback(() => {
|
|
@@ -123,7 +123,7 @@ export const useInputContext = () => {
|
|
|
123
123
|
const context = useContext(InputContext);
|
|
124
124
|
if (!context) {
|
|
125
125
|
throw new Error(
|
|
126
|
-
"useInputContext must be used within an InputContextProvider"
|
|
126
|
+
"useInputContext must be used within an InputContextProvider",
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
return context;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Chips } from "../../../chips";
|
|
3
|
-
import { useSelectedOptionsContext } from "./selectedOptionsContext";
|
|
4
3
|
import { useInputContext } from "../Input/inputContext";
|
|
4
|
+
import { useSelectedOptionsContext } from "./selectedOptionsContext";
|
|
5
5
|
|
|
6
6
|
interface SelectedOptionsProps {
|
|
7
7
|
selectedOptions?: string[];
|
|
@@ -19,12 +19,12 @@ type SelectedOptionsContextType = {
|
|
|
19
19
|
setSelectedOptions: (any) => void;
|
|
20
20
|
toggleOption: (
|
|
21
21
|
option: string,
|
|
22
|
-
event: React.KeyboardEvent | React.PointerEvent
|
|
22
|
+
event: React.KeyboardEvent | React.PointerEvent,
|
|
23
23
|
) => void;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
const SelectedOptionsContext = createContext<SelectedOptionsContextType>(
|
|
27
|
-
{} as SelectedOptionsContextType
|
|
27
|
+
{} as SelectedOptionsContextType,
|
|
28
28
|
);
|
|
29
29
|
|
|
30
30
|
export const SelectedOptionsProvider = ({
|
|
@@ -59,7 +59,7 @@ export const SelectedOptionsProvider = ({
|
|
|
59
59
|
const selectedOptions = useMemo(
|
|
60
60
|
() =>
|
|
61
61
|
externalSelectedOptions ?? [...customOptions, ...internalSelectedOptions],
|
|
62
|
-
[customOptions, externalSelectedOptions, internalSelectedOptions]
|
|
62
|
+
[customOptions, externalSelectedOptions, internalSelectedOptions],
|
|
63
63
|
);
|
|
64
64
|
|
|
65
65
|
const addSelectedOption = useCallback(
|
|
@@ -88,7 +88,7 @@ export const SelectedOptionsProvider = ({
|
|
|
88
88
|
onToggleSelected,
|
|
89
89
|
options,
|
|
90
90
|
setCustomOptions,
|
|
91
|
-
]
|
|
91
|
+
],
|
|
92
92
|
);
|
|
93
93
|
|
|
94
94
|
const removeSelectedOption = useCallback(
|
|
@@ -99,13 +99,13 @@ export const SelectedOptionsProvider = ({
|
|
|
99
99
|
} else {
|
|
100
100
|
setSelectedOptions((oldSelectedOptions) =>
|
|
101
101
|
oldSelectedOptions.filter(
|
|
102
|
-
(selectedOption) => selectedOption !== option
|
|
103
|
-
)
|
|
102
|
+
(selectedOption) => selectedOption !== option,
|
|
103
|
+
),
|
|
104
104
|
);
|
|
105
105
|
}
|
|
106
106
|
onToggleSelected?.(option, false, isCustomOption);
|
|
107
107
|
},
|
|
108
|
-
[customOptions, onToggleSelected, removeCustomOption]
|
|
108
|
+
[customOptions, onToggleSelected, removeCustomOption],
|
|
109
109
|
);
|
|
110
110
|
|
|
111
111
|
const toggleOption = useCallback(
|
|
@@ -124,7 +124,7 @@ export const SelectedOptionsProvider = ({
|
|
|
124
124
|
focusInput,
|
|
125
125
|
removeSelectedOption,
|
|
126
126
|
selectedOptions,
|
|
127
|
-
]
|
|
127
|
+
],
|
|
128
128
|
);
|
|
129
129
|
|
|
130
130
|
const prevSelectedOptions = usePrevious<string[]>(selectedOptions);
|
|
@@ -150,7 +150,7 @@ export const useSelectedOptionsContext = () => {
|
|
|
150
150
|
const context = useContext(SelectedOptionsContext);
|
|
151
151
|
if (!context) {
|
|
152
152
|
throw new Error(
|
|
153
|
-
"useSelectedOptionsContext must be used within a SelectedOptionsProvider"
|
|
153
|
+
"useSelectedOptionsContext must be used within a SelectedOptionsProvider",
|
|
154
154
|
);
|
|
155
155
|
}
|
|
156
156
|
return context;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { forwardRef } from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ChevronDownIcon, ChevronUpIcon } from "@navikt/aksel-icons";
|
|
4
3
|
import { useFilteredOptionsContext } from "./FilteredOptions/filteredOptionsContext";
|
|
5
4
|
|
|
6
5
|
interface ToggleListButtonProps {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { expect, jest } from "@storybook/jest";
|
|
1
2
|
import { Meta, StoryFn, StoryObj } from "@storybook/react";
|
|
2
|
-
import React, { useState, useId, useMemo } from "react";
|
|
3
3
|
import { userEvent, within } from "@storybook/testing-library";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import React, { useId, useMemo, useState } from "react";
|
|
5
|
+
import { Chips, ComboboxProps, TextField, UNSAFE_Combobox } from "../../index";
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
title: "ds-react/Combobox",
|
|
@@ -207,11 +207,11 @@ export const Controlled: StoryFn<{
|
|
|
207
207
|
const id = useId();
|
|
208
208
|
const [value, setValue] = useState(props.value);
|
|
209
209
|
const [selectedOptions, setSelectedOptions] = useState(
|
|
210
|
-
props.initialSelectedOptions
|
|
210
|
+
props.initialSelectedOptions,
|
|
211
211
|
);
|
|
212
212
|
const filteredOptions = useMemo(
|
|
213
213
|
() => props.options.filter((option) => option.includes(value)),
|
|
214
|
-
[props.options, value]
|
|
214
|
+
[props.options, value],
|
|
215
215
|
);
|
|
216
216
|
|
|
217
217
|
const onToggleSelected = (option: string, isSelected: boolean) => {
|
|
@@ -536,20 +536,20 @@ export const TestHoverAndFocusSwitching: StoryObject = {
|
|
|
536
536
|
await sleep(250);
|
|
537
537
|
const bananaOption = canvas.getByRole("option", { name: "banana" });
|
|
538
538
|
expect(getInput().getAttribute("aria-activedescendant")).toBe(
|
|
539
|
-
bananaOption.getAttribute("id")
|
|
539
|
+
bananaOption.getAttribute("id"),
|
|
540
540
|
);
|
|
541
541
|
|
|
542
542
|
userEvent.keyboard("{ArrowDown}");
|
|
543
543
|
await sleep(250);
|
|
544
544
|
const appleOption = canvas.getByRole("option", { name: "apple" });
|
|
545
545
|
expect(getInput().getAttribute("aria-activedescendant")).toBe(
|
|
546
|
-
appleOption.getAttribute("id")
|
|
546
|
+
appleOption.getAttribute("id"),
|
|
547
547
|
);
|
|
548
548
|
|
|
549
549
|
userEvent.hover(bananaOption);
|
|
550
550
|
await sleep(250);
|
|
551
551
|
expect(getInput().getAttribute("aria-activedescendant")).toBe(
|
|
552
|
-
bananaOption.getAttribute("id")
|
|
552
|
+
bananaOption.getAttribute("id"),
|
|
553
553
|
);
|
|
554
554
|
},
|
|
555
555
|
};
|