@norges-domstoler/dds-components 0.0.0-dev-20240223144112 → 0.0.0-dev-20240223152935
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/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +41 -71
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -96
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -752,11 +752,11 @@ declare const isKeyboardEvent: (e: Event | KeyboardEvent$1<Element>) => e is Key
|
|
|
752
752
|
* }
|
|
753
753
|
* ```
|
|
754
754
|
* @param size antall elementer i gruppen.
|
|
755
|
-
* @param
|
|
755
|
+
* @param active om fokus skal kontrolleres av hooken. Når status blir inaktiv vil fokusrekkefølge nullstilles.
|
|
756
756
|
* @param direction retning elementene blas i.
|
|
757
757
|
* @returns hook par: indeksen til fokuserte elemenentet og funksjonen som håndterer fokus.
|
|
758
758
|
*/
|
|
759
|
-
declare function useRoveFocus(size?: number,
|
|
759
|
+
declare function useRoveFocus(size?: number, active?: boolean, direction?: Direction$1): [number, Dispatch<SetStateAction<number>>];
|
|
760
760
|
|
|
761
761
|
declare enum ScreenSize {
|
|
762
762
|
XSmall = 0,
|
package/dist/index.d.ts
CHANGED
|
@@ -752,11 +752,11 @@ declare const isKeyboardEvent: (e: Event | KeyboardEvent$1<Element>) => e is Key
|
|
|
752
752
|
* }
|
|
753
753
|
* ```
|
|
754
754
|
* @param size antall elementer i gruppen.
|
|
755
|
-
* @param
|
|
755
|
+
* @param active om fokus skal kontrolleres av hooken. Når status blir inaktiv vil fokusrekkefølge nullstilles.
|
|
756
756
|
* @param direction retning elementene blas i.
|
|
757
757
|
* @returns hook par: indeksen til fokuserte elemenentet og funksjonen som håndterer fokus.
|
|
758
758
|
*/
|
|
759
|
-
declare function useRoveFocus(size?: number,
|
|
759
|
+
declare function useRoveFocus(size?: number, active?: boolean, direction?: Direction$1): [number, Dispatch<SetStateAction<number>>];
|
|
760
760
|
|
|
761
761
|
declare enum ScreenSize {
|
|
762
762
|
XSmall = 0,
|
package/dist/index.js
CHANGED
|
@@ -3073,7 +3073,7 @@ function useReturnFocusOnBlur(active, onBlur, triggerElement) {
|
|
|
3073
3073
|
// src/hooks/useRoveFocus.tsx
|
|
3074
3074
|
var import_react10 = require("react");
|
|
3075
3075
|
var isKeyboardEvent = (e) => e.key !== void 0;
|
|
3076
|
-
function useRoveFocus(size2,
|
|
3076
|
+
function useRoveFocus(size2, active, direction = "column") {
|
|
3077
3077
|
const [currentFocusIndex, setCurrentFocusIndex] = (0, import_react10.useState)(-1);
|
|
3078
3078
|
const nextKey = direction === "row" ? "ArrowRight" : "ArrowDown";
|
|
3079
3079
|
const previousKey = direction === "row" ? "ArrowLeft" : "ArrowUp";
|
|
@@ -3081,31 +3081,30 @@ function useRoveFocus(size2, reset, direction = "column") {
|
|
|
3081
3081
|
(e) => {
|
|
3082
3082
|
if (!size2 || !isKeyboardEvent(e))
|
|
3083
3083
|
return;
|
|
3084
|
-
if (reset)
|
|
3085
|
-
setCurrentFocusIndex(-1);
|
|
3086
3084
|
if (e.key === nextKey) {
|
|
3087
3085
|
e.preventDefault();
|
|
3088
|
-
setCurrentFocusIndex(
|
|
3089
|
-
currentFocusIndex === size2 - 1 ? 0 : currentFocusIndex + 1
|
|
3090
|
-
);
|
|
3086
|
+
setCurrentFocusIndex((prev) => prev === size2 - 1 ? 0 : prev + 1);
|
|
3091
3087
|
} else if (e.key === previousKey) {
|
|
3092
3088
|
e.preventDefault();
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
}
|
|
3098
|
-
setCurrentFocusIndex(size2 - 1);
|
|
3089
|
+
setCurrentFocusIndex((prev) => {
|
|
3090
|
+
if (prev === -1 || prev === 0)
|
|
3091
|
+
return size2 - 1;
|
|
3092
|
+
return prev - 1;
|
|
3093
|
+
});
|
|
3099
3094
|
}
|
|
3100
3095
|
},
|
|
3101
|
-
[size2,
|
|
3096
|
+
[size2, setCurrentFocusIndex]
|
|
3102
3097
|
);
|
|
3103
3098
|
(0, import_react10.useEffect)(() => {
|
|
3099
|
+
if (!active) {
|
|
3100
|
+
setCurrentFocusIndex(-1);
|
|
3101
|
+
return;
|
|
3102
|
+
}
|
|
3104
3103
|
document.addEventListener("keydown", handleKeyDown, false);
|
|
3105
3104
|
return () => {
|
|
3106
3105
|
document.removeEventListener("keydown", handleKeyDown, false);
|
|
3107
3106
|
};
|
|
3108
|
-
}, [handleKeyDown]);
|
|
3107
|
+
}, [handleKeyDown, active]);
|
|
3109
3108
|
return [currentFocusIndex, setCurrentFocusIndex];
|
|
3110
3109
|
}
|
|
3111
3110
|
|
|
@@ -4387,18 +4386,7 @@ var IconWrapper = import_styled_components17.default.span`
|
|
|
4387
4386
|
var isAnchorProps2 = (props) => props.href !== void 0;
|
|
4388
4387
|
var isButtonProps = (props) => props.href === void 0 && props.onClick !== void 0;
|
|
4389
4388
|
var OverflowMenuItem = (0, import_react21.forwardRef)((props, ref) => {
|
|
4390
|
-
const {
|
|
4391
|
-
title: title3,
|
|
4392
|
-
icon: icon12,
|
|
4393
|
-
focus,
|
|
4394
|
-
setFocus,
|
|
4395
|
-
index,
|
|
4396
|
-
id,
|
|
4397
|
-
className,
|
|
4398
|
-
htmlProps = {},
|
|
4399
|
-
...rest
|
|
4400
|
-
} = props;
|
|
4401
|
-
const { onKeyDown } = htmlProps;
|
|
4389
|
+
const { title: title3, icon: icon12, focus, id, className, htmlProps = {}, ...rest } = props;
|
|
4402
4390
|
let href;
|
|
4403
4391
|
let onClick;
|
|
4404
4392
|
if (isAnchorProps2(props)) {
|
|
@@ -4414,23 +4402,8 @@ var OverflowMenuItem = (0, import_react21.forwardRef)((props, ref) => {
|
|
|
4414
4402
|
(_a = itemRef.current) == null ? void 0 : _a.focus();
|
|
4415
4403
|
}
|
|
4416
4404
|
}, [focus]);
|
|
4417
|
-
const handleSelect = (0, import_react21.useCallback)(() => {
|
|
4418
|
-
if (setFocus && index) {
|
|
4419
|
-
setFocus(index);
|
|
4420
|
-
}
|
|
4421
|
-
}, [index, setFocus]);
|
|
4422
|
-
const handleOnClick = (e) => {
|
|
4423
|
-
handleSelect();
|
|
4424
|
-
onClick && onClick(e);
|
|
4425
|
-
};
|
|
4426
|
-
const handleOnKeyDown = (e) => {
|
|
4427
|
-
handleSelect();
|
|
4428
|
-
onKeyDown && onKeyDown(e);
|
|
4429
|
-
};
|
|
4430
4405
|
const linkProps = {
|
|
4431
4406
|
href,
|
|
4432
|
-
onClick: handleOnClick,
|
|
4433
|
-
onKeyDown: handleOnKeyDown,
|
|
4434
4407
|
role: "menuitem",
|
|
4435
4408
|
tabIndex: focus ? 0 : -1
|
|
4436
4409
|
};
|
|
@@ -4890,13 +4863,12 @@ var OverflowMenu = (0, import_react25.forwardRef)(
|
|
|
4890
4863
|
hasNavItems && interactiveItems.push(...navItems);
|
|
4891
4864
|
hasContextItems && interactiveItems.push(...items);
|
|
4892
4865
|
const hasInteractiveItems = interactiveItems.length > 0;
|
|
4893
|
-
const [focus
|
|
4866
|
+
const [focus] = useRoveFocus(interactiveItems == null ? void 0 : interactiveItems.length, isOpen);
|
|
4894
4867
|
const interactiveItemsList = hasInteractiveItems ? interactiveItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime177.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime177.jsx)(
|
|
4895
4868
|
OverflowMenuItem,
|
|
4896
4869
|
{
|
|
4897
4870
|
index,
|
|
4898
4871
|
focus: focus === index && isOpen,
|
|
4899
|
-
setFocus,
|
|
4900
4872
|
icon: hasInteractiveUser && index === 0 ? PersonIcon : void 0,
|
|
4901
4873
|
...item,
|
|
4902
4874
|
onClick: (e) => {
|
|
@@ -11618,7 +11590,7 @@ var SearchSuggestions = (0, import_react85.forwardRef)((props, ref) => {
|
|
|
11618
11590
|
searchId,
|
|
11619
11591
|
"suggestions-header"
|
|
11620
11592
|
);
|
|
11621
|
-
const [focus
|
|
11593
|
+
const [focus] = useRoveFocus(suggestions == null ? void 0 : suggestions.length, showSuggestions);
|
|
11622
11594
|
const suggestionsToRender = maxSuggestions ? suggestions == null ? void 0 : suggestions.slice(maxSuggestions) : suggestions;
|
|
11623
11595
|
const renderedSuggestions = /* @__PURE__ */ (0, import_jsx_runtime244.jsx)(SuggestionsList, { role: "listbox", "aria-labelledby": suggestionsHeaderId, children: suggestionsToRender.map((suggestion, index) => {
|
|
11624
11596
|
return /* @__PURE__ */ (0, import_jsx_runtime244.jsx)("li", { role: "option", children: /* @__PURE__ */ (0, import_jsx_runtime244.jsx)(
|
|
@@ -11626,7 +11598,6 @@ var SearchSuggestions = (0, import_react85.forwardRef)((props, ref) => {
|
|
|
11626
11598
|
{
|
|
11627
11599
|
index,
|
|
11628
11600
|
focus: focus === index && showSuggestions,
|
|
11629
|
-
setFocus,
|
|
11630
11601
|
"aria-label": `s\xF8k p\xE5 ${suggestion}`,
|
|
11631
11602
|
onClick: onSuggestionClick,
|
|
11632
11603
|
title: suggestion,
|
|
@@ -13531,19 +13502,13 @@ var Tab = (0, import_react110.forwardRef)((props, ref) => {
|
|
|
13531
13502
|
useSetTabWidth(index, width);
|
|
13532
13503
|
const itemRef = (0, import_react110.useRef)(null);
|
|
13533
13504
|
const combinedRef = useCombinedRef(ref, itemRef);
|
|
13534
|
-
const {
|
|
13505
|
+
const { tabContentDirection } = useTabsContext();
|
|
13535
13506
|
(0, import_react110.useEffect)(() => {
|
|
13536
13507
|
var _a;
|
|
13537
13508
|
if (focus) {
|
|
13538
13509
|
(_a = itemRef.current) == null ? void 0 : _a.focus();
|
|
13539
|
-
setHasTabFocus(true);
|
|
13540
13510
|
}
|
|
13541
13511
|
}, [focus]);
|
|
13542
|
-
useOnKeyDown("Tab", () => {
|
|
13543
|
-
var _a;
|
|
13544
|
-
setHasTabFocus(false);
|
|
13545
|
-
(_a = tabPanelsRef == null ? void 0 : tabPanelsRef.current) == null ? void 0 : _a.focus();
|
|
13546
|
-
});
|
|
13547
13512
|
const handleSelect = (0, import_react110.useCallback)(() => {
|
|
13548
13513
|
if (setFocus && index) {
|
|
13549
13514
|
setFocus(index);
|
|
@@ -13617,12 +13582,11 @@ var TabList = (0, import_react111.forwardRef)(
|
|
|
13617
13582
|
handleTabChange,
|
|
13618
13583
|
tabListRef,
|
|
13619
13584
|
hasTabFocus,
|
|
13620
|
-
tabPanelsRef,
|
|
13621
13585
|
setHasTabFocus
|
|
13622
13586
|
} = useTabsContext();
|
|
13623
13587
|
const uniqueId = id != null ? id : `${tabsId}-tablist`;
|
|
13624
13588
|
const childrenArray = import_react111.Children.toArray(children).length;
|
|
13625
|
-
const [focus, setFocus] = useRoveFocus(childrenArray,
|
|
13589
|
+
const [focus, setFocus] = useRoveFocus(childrenArray, hasTabFocus, "row");
|
|
13626
13590
|
const combinedRef = useCombinedRef(ref, tabListRef);
|
|
13627
13591
|
const tabListChildren = import_react111.Children.map(children, (child, index) => {
|
|
13628
13592
|
return (0, import_react111.isValidElement)(child) && (0, import_react111.cloneElement)(child, {
|
|
@@ -13636,28 +13600,34 @@ var TabList = (0, import_react111.forwardRef)(
|
|
|
13636
13600
|
});
|
|
13637
13601
|
});
|
|
13638
13602
|
const [widths, setWidths] = (0, import_react111.useState)([]);
|
|
13639
|
-
useOnKeyDown("Tab", () => {
|
|
13640
|
-
var _a;
|
|
13641
|
-
setHasTabFocus(false);
|
|
13642
|
-
(_a = tabPanelsRef == null ? void 0 : tabPanelsRef.current) == null ? void 0 : _a.focus();
|
|
13643
|
-
});
|
|
13644
|
-
useOnClickOutside((tabListRef == null ? void 0 : tabListRef.current) || null, () => {
|
|
13645
|
-
setHasTabFocus(false);
|
|
13646
|
-
});
|
|
13647
13603
|
const handleOnFocus = (event) => {
|
|
13648
13604
|
setHasTabFocus(true);
|
|
13649
13605
|
onFocus && onFocus(event);
|
|
13650
13606
|
};
|
|
13651
|
-
const
|
|
13652
|
-
|
|
13653
|
-
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
|
|
13657
|
-
|
|
13658
|
-
|
|
13607
|
+
const handleOnBlur = (event) => {
|
|
13608
|
+
var _a;
|
|
13609
|
+
if ((tabListRef == null ? void 0 : tabListRef.current) === event.relatedTarget) {
|
|
13610
|
+
setFocus(-1);
|
|
13611
|
+
}
|
|
13612
|
+
if (!((_a = tabListRef == null ? void 0 : tabListRef.current) == null ? void 0 : _a.contains(event.relatedTarget))) {
|
|
13613
|
+
setHasTabFocus(false);
|
|
13614
|
+
}
|
|
13659
13615
|
};
|
|
13660
|
-
return /* @__PURE__ */ (0, import_jsx_runtime266.jsx)(TabWidthContextProvider, { onChangeWidths: setWidths, children: /* @__PURE__ */ (0, import_jsx_runtime266.jsx)(
|
|
13616
|
+
return /* @__PURE__ */ (0, import_jsx_runtime266.jsx)(TabWidthContextProvider, { onChangeWidths: setWidths, children: /* @__PURE__ */ (0, import_jsx_runtime266.jsx)(
|
|
13617
|
+
TabRow,
|
|
13618
|
+
{
|
|
13619
|
+
...rest,
|
|
13620
|
+
ref: combinedRef,
|
|
13621
|
+
role: "tablist",
|
|
13622
|
+
"aria-label": "Bruk venste og h\xF8yre piltast for \xE5 bla",
|
|
13623
|
+
id: uniqueId,
|
|
13624
|
+
tabIndex: 0,
|
|
13625
|
+
onFocus: handleOnFocus,
|
|
13626
|
+
onBlur: handleOnBlur,
|
|
13627
|
+
$gridTemplateColumns: widths.join(" "),
|
|
13628
|
+
children: tabListChildren
|
|
13629
|
+
}
|
|
13630
|
+
) });
|
|
13661
13631
|
}
|
|
13662
13632
|
);
|
|
13663
13633
|
TabList.displayName = "TabList";
|