@react-aria/toolbar 3.0.0-beta.23 → 3.0.0-beta.25

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/import.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {useToolbar as $2680b1829e803644$export$fa142eb1681c520} from "./useToolbar.mjs";
1
+ import {useToolbar as $3147d56795045efa$re_export$useToolbar} from "react-aria/useToolbar";
2
2
 
3
3
  /*
4
4
  * Copyright 2023 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useToolbar as $2680b1829e803644$export$fa142eb1681c520} from "./useToolb
13
13
  */
14
14
 
15
15
 
16
- export {$2680b1829e803644$export$fa142eb1681c520 as useToolbar};
16
+ export {$3147d56795045efa$re_export$useToolbar as useToolbar};
17
17
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,22 +1,11 @@
1
- var $b132ee173e26a273$exports = require("./useToolbar.main.js");
1
+ var $4E5BG$reactariauseToolbar = require("react-aria/useToolbar");
2
2
 
3
3
 
4
- function $parcel$exportWildcard(dest, source) {
5
- Object.keys(source).forEach(function(key) {
6
- if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
7
- return;
8
- }
9
-
10
- Object.defineProperty(dest, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return source[key];
14
- }
15
- });
16
- });
17
-
18
- return dest;
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
19
6
  }
7
+
8
+ $parcel$export(module.exports, "useToolbar", function () { return $4E5BG$reactariauseToolbar.useToolbar; });
20
9
  /*
21
10
  * Copyright 2023 Adobe. All rights reserved.
22
11
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -28,7 +17,6 @@ function $parcel$exportWildcard(dest, source) {
28
17
  * OF ANY KIND, either express or implied. See the License for the specific language
29
18
  * governing permissions and limitations under the License.
30
19
  */
31
- $parcel$exportWildcard(module.exports, $b132ee173e26a273$exports);
32
20
 
33
21
 
34
22
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/toolbar/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useToolbar';\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/toolbar/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useToolbar} from 'react-aria/useToolbar';\n\nexport type {AriaToolbarProps, ToolbarAria} from 'react-aria/useToolbar';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {useToolbar as $2680b1829e803644$export$fa142eb1681c520} from "./useToolbar.module.js";
1
+ import {useToolbar as $3147d56795045efa$re_export$useToolbar} from "react-aria/useToolbar";
2
2
 
3
3
  /*
4
4
  * Copyright 2023 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useToolbar as $2680b1829e803644$export$fa142eb1681c520} from "./useToolb
13
13
  */
14
14
 
15
15
 
16
- export {$2680b1829e803644$export$fa142eb1681c520 as useToolbar};
16
+ export {$3147d56795045efa$re_export$useToolbar as useToolbar};
17
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/toolbar/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useToolbar';\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/toolbar/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useToolbar} from 'react-aria/useToolbar';\n\nexport type {AriaToolbarProps, ToolbarAria} from 'react-aria/useToolbar';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,2 @@
1
+ export { useToolbar } from 'react-aria/useToolbar';
2
+ export type { AriaToolbarProps, ToolbarAria } from 'react-aria/useToolbar';
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@react-aria/toolbar",
3
- "version": "3.0.0-beta.23",
3
+ "version": "3.0.0-beta.25",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
- "types": "dist/types.d.ts",
8
+ "types": "dist/types/src/index.d.ts",
9
9
  "exports": {
10
- "source": "./src/index.ts",
11
- "types": [
12
- "./dist/types.d.ts",
13
- "./src/index.ts"
14
- ],
15
- "import": "./dist/import.mjs",
16
- "require": "./dist/main.js"
10
+ ".": {
11
+ "source": "./src/index.ts",
12
+ "types": "./dist/types/src/index.d.ts",
13
+ "import": "./dist/import.mjs",
14
+ "require": "./dist/main.js"
15
+ },
16
+ "./package.json": "./package.json"
17
17
  },
18
18
  "source": "src/index.ts",
19
19
  "files": [
@@ -26,11 +26,8 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-aria/focus": "^3.21.4",
30
- "@react-aria/i18n": "^3.12.15",
31
- "@react-aria/utils": "^3.33.0",
32
- "@react-types/shared": "^3.33.0",
33
- "@swc/helpers": "^0.5.0"
29
+ "@swc/helpers": "^0.5.0",
30
+ "react-aria": "3.48.0"
34
31
  },
35
32
  "peerDependencies": {
36
33
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
@@ -39,5 +36,8 @@
39
36
  "publishConfig": {
40
37
  "access": "public"
41
38
  },
42
- "gitHead": "66e51757606b43a89ed02c574ca24517323a2ab9"
39
+ "targets": {
40
+ "types": false
41
+ },
42
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
43
43
  }
package/src/index.ts CHANGED
@@ -10,4 +10,6 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export * from './useToolbar';
13
+ export {useToolbar} from 'react-aria/useToolbar';
14
+
15
+ export type {AriaToolbarProps, ToolbarAria} from 'react-aria/useToolbar';
package/dist/types.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { AriaLabelingProps, Orientation, RefObject } from "@react-types/shared";
2
- import { HTMLAttributes } from "react";
3
- export interface AriaToolbarProps extends AriaLabelingProps {
4
- /**
5
- * The orientation of the entire toolbar.
6
- * @default 'horizontal'
7
- */
8
- orientation?: Orientation;
9
- }
10
- export interface ToolbarAria {
11
- /**
12
- * Props for the toolbar container.
13
- */
14
- toolbarProps: HTMLAttributes<HTMLElement>;
15
- }
16
- /**
17
- * Provides the behavior and accessibility implementation for a toolbar.
18
- * A toolbar is a container for a set of interactive controls with arrow key navigation.
19
- * @param props - Props to be applied to the toolbar.
20
- * @param ref - A ref to a DOM element for the toolbar.
21
- */
22
- export function useToolbar(props: AriaToolbarProps, ref: RefObject<HTMLElement | null>): ToolbarAria;
23
-
24
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAkBA,iCAAkC,SAAQ,iBAAiB;IACzD;;;OAGG;IACH,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B;AAED;IACE;;OAEG;IACH,YAAY,EAAE,eAAe,WAAW,CAAC,CAAA;CAC1C;AAED;;;;;GAKG;AACH,2BAA2B,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,GAAG,WAAW,CA2FnG","sources":["packages/@react-aria/toolbar/src/packages/@react-aria/toolbar/src/useToolbar.ts","packages/@react-aria/toolbar/src/packages/@react-aria/toolbar/src/index.ts","packages/@react-aria/toolbar/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useToolbar';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -1,96 +0,0 @@
1
- var $37ePF$reactariafocus = require("@react-aria/focus");
2
- var $37ePF$reactariautils = require("@react-aria/utils");
3
- var $37ePF$react = require("react");
4
- var $37ePF$reactariai18n = require("@react-aria/i18n");
5
-
6
-
7
- function $parcel$export(e, n, v, s) {
8
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
- }
10
-
11
- $parcel$export(module.exports, "useToolbar", () => $b132ee173e26a273$export$fa142eb1681c520);
12
- /*
13
- * Copyright 2023 Adobe. All rights reserved.
14
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
15
- * you may not use this file except in compliance with the License. You may obtain a copy
16
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
17
- *
18
- * Unless required by applicable law or agreed to in writing, software distributed under
19
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
20
- * OF ANY KIND, either express or implied. See the License for the specific language
21
- * governing permissions and limitations under the License.
22
- */
23
-
24
-
25
-
26
- function $b132ee173e26a273$export$fa142eb1681c520(props, ref) {
27
- const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, orientation: orientation = 'horizontal' } = props;
28
- let [isInToolbar, setInToolbar] = (0, $37ePF$react.useState)(false);
29
- // should be safe because re-calling set state with the same value it already has is a no-op
30
- // this will allow us to react should a parent re-render and change its role though
31
- // eslint-disable-next-line react-hooks/exhaustive-deps
32
- (0, $37ePF$reactariautils.useLayoutEffect)(()=>{
33
- var _ref_current_parentElement;
34
- setInToolbar(!!(ref.current && ((_ref_current_parentElement = ref.current.parentElement) === null || _ref_current_parentElement === void 0 ? void 0 : _ref_current_parentElement.closest('[role="toolbar"]'))));
35
- });
36
- const { direction: direction } = (0, $37ePF$reactariai18n.useLocale)();
37
- const shouldReverse = direction === 'rtl' && orientation === 'horizontal';
38
- let focusManager = (0, $37ePF$reactariafocus.createFocusManager)(ref);
39
- const onKeyDown = (e)=>{
40
- // don't handle portalled events
41
- if (!(0, $37ePF$reactariautils.nodeContains)(e.currentTarget, e.target)) return;
42
- if (orientation === 'horizontal' && e.key === 'ArrowRight' || orientation === 'vertical' && e.key === 'ArrowDown') {
43
- if (shouldReverse) focusManager.focusPrevious();
44
- else focusManager.focusNext();
45
- } else if (orientation === 'horizontal' && e.key === 'ArrowLeft' || orientation === 'vertical' && e.key === 'ArrowUp') {
46
- if (shouldReverse) focusManager.focusNext();
47
- else focusManager.focusPrevious();
48
- } else if (e.key === 'Tab') {
49
- // When the tab key is pressed, we want to move focus
50
- // out of the entire toolbar. To do this, move focus
51
- // to the first or last focusable child, and let the
52
- // browser handle the Tab key as usual from there.
53
- e.stopPropagation();
54
- lastFocused.current = document.activeElement;
55
- if (e.shiftKey) focusManager.focusFirst();
56
- else focusManager.focusLast();
57
- return;
58
- } else // if we didn't handle anything, return early so we don't preventDefault
59
- return;
60
- // Prevent arrow keys from being handled by nested action groups.
61
- e.stopPropagation();
62
- e.preventDefault();
63
- };
64
- // Record the last focused child when focus moves out of the toolbar.
65
- const lastFocused = (0, $37ePF$react.useRef)(null);
66
- const onBlur = (e)=>{
67
- if (!(0, $37ePF$reactariautils.nodeContains)(e.currentTarget, e.relatedTarget) && !lastFocused.current) lastFocused.current = e.target;
68
- };
69
- // Restore focus to the last focused child when focus returns into the toolbar.
70
- // If the element was removed, do nothing, either the first item in the first group,
71
- // or the last item in the last group will be focused, depending on direction.
72
- const onFocus = (e)=>{
73
- if (lastFocused.current && !(0, $37ePF$reactariautils.nodeContains)(e.currentTarget, e.relatedTarget) && (0, $37ePF$reactariautils.nodeContains)(ref.current, e.target)) {
74
- var _lastFocused_current;
75
- (_lastFocused_current = lastFocused.current) === null || _lastFocused_current === void 0 ? void 0 : _lastFocused_current.focus();
76
- lastFocused.current = null;
77
- }
78
- };
79
- return {
80
- toolbarProps: {
81
- ...(0, $37ePF$reactariautils.filterDOMProps)(props, {
82
- labelable: true
83
- }),
84
- role: !isInToolbar ? 'toolbar' : 'group',
85
- 'aria-orientation': orientation,
86
- 'aria-label': ariaLabel,
87
- 'aria-labelledby': ariaLabel == null ? ariaLabelledBy : undefined,
88
- onKeyDownCapture: !isInToolbar ? onKeyDown : undefined,
89
- onFocusCapture: !isInToolbar ? onFocus : undefined,
90
- onBlurCapture: !isInToolbar ? onBlur : undefined
91
- }
92
- };
93
- }
94
-
95
-
96
- //# sourceMappingURL=useToolbar.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA6BM,SAAS,yCAAW,KAAuB,EAAE,GAAkC;IACpF,MAAM,EACJ,cAAc,SAAS,EACvB,mBAAmB,cAAc,eACjC,cAAc,cACf,GAAG;IACJ,IAAI,CAAC,aAAa,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC3C,4FAA4F;IAC5F,mFAAmF;IACnF,uDAAuD;IACvD,CAAA,GAAA,qCAAc,EAAE;YACiB;QAA/B,aAAa,CAAC,CAAE,CAAA,IAAI,OAAO,MAAI,6BAAA,IAAI,OAAO,CAAC,aAAa,cAAzB,iDAAA,2BAA2B,OAAO,CAAC,oBAAkB;IACtF;IACA,MAAM,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC5B,MAAM,gBAAgB,cAAc,SAAS,gBAAgB;IAC7D,IAAI,eAAe,CAAA,GAAA,wCAAiB,EAAE;IAEtC,MAAM,YAAkC,CAAC;QACvC,gCAAgC;QAChC,IAAI,CAAC,CAAA,GAAA,kCAAW,EAAE,EAAE,aAAa,EAAE,EAAE,MAAM,GACzC;QAEF,IACE,AAAC,gBAAgB,gBAAgB,EAAE,GAAG,KAAK,gBACvC,gBAAgB,cAAc,EAAE,GAAG,KAAK;YAC5C,IAAI,eACF,aAAa,aAAa;iBAE1B,aAAa,SAAS;eAEnB,IACL,AAAC,gBAAgB,gBAAgB,EAAE,GAAG,KAAK,eACvC,gBAAgB,cAAc,EAAE,GAAG,KAAK;YAC5C,IAAI,eACF,aAAa,SAAS;iBAEtB,aAAa,aAAa;eAEvB,IAAI,EAAE,GAAG,KAAK,OAAO;YAC1B,qDAAqD;YACrD,oDAAoD;YACpD,oDAAoD;YACpD,kDAAkD;YAClD,EAAE,eAAe;YACjB,YAAY,OAAO,GAAG,SAAS,aAAa;YAC5C,IAAI,EAAE,QAAQ,EACZ,aAAa,UAAU;iBAEvB,aAAa,SAAS;YAExB;QACF,OACE,wEAAwE;QACxE;QAGF,iEAAiE;QACjE,EAAE,eAAe;QACjB,EAAE,cAAc;IAClB;IAEA,qEAAqE;IACrE,MAAM,cAAc,CAAA,GAAA,mBAAK,EAAsB;IAC/C,MAAM,SAAS,CAAC;QACd,IAAI,CAAC,CAAA,GAAA,kCAAW,EAAE,EAAE,aAAa,EAAE,EAAE,aAAa,KAAK,CAAC,YAAY,OAAO,EACzE,YAAY,OAAO,GAAG,EAAE,MAAM;IAElC;IAEA,+EAA+E;IAC/E,oFAAoF;IACpF,8EAA8E;IAC9E,MAAM,UAAU,CAAC;QACf,IAAI,YAAY,OAAO,IAAI,CAAC,CAAA,GAAA,kCAAW,EAAE,EAAE,aAAa,EAAE,EAAE,aAAa,KAAK,CAAA,GAAA,kCAAW,EAAE,IAAI,OAAO,EAAE,EAAE,MAAM,GAAG;gBACjH;aAAA,uBAAA,YAAY,OAAO,cAAnB,2CAAA,qBAAqB,KAAK;YAC1B,YAAY,OAAO,GAAG;QACxB;IACF;IAEA,OAAO;QACL,cAAc;YACZ,GAAG,CAAA,GAAA,oCAAa,EAAE,OAAO;gBAAC,WAAW;YAAI,EAAE;YAC3C,MAAM,CAAC,cAAc,YAAY;YACjC,oBAAoB;YACpB,cAAc;YACd,mBAAmB,aAAa,OAAO,iBAAiB;YACxD,kBAAkB,CAAC,cAAc,YAAY;YAC7C,gBAAgB,CAAC,cAAc,UAAU;YACzC,eAAe,CAAC,cAAc,SAAS;QACzC;IACF;AACF","sources":["packages/@react-aria/toolbar/src/useToolbar.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, Orientation, RefObject} from '@react-types/shared';\nimport {createFocusManager} from '@react-aria/focus';\nimport {filterDOMProps, nodeContains, useLayoutEffect} from '@react-aria/utils';\nimport {HTMLAttributes, KeyboardEventHandler, useRef, useState} from 'react';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaToolbarProps extends AriaLabelingProps {\n /**\n * The orientation of the entire toolbar.\n * @default 'horizontal'\n */\n orientation?: Orientation\n}\n\nexport interface ToolbarAria {\n /**\n * Props for the toolbar container.\n */\n toolbarProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toolbar.\n * A toolbar is a container for a set of interactive controls with arrow key navigation.\n * @param props - Props to be applied to the toolbar.\n * @param ref - A ref to a DOM element for the toolbar.\n */\nexport function useToolbar(props: AriaToolbarProps, ref: RefObject<HTMLElement | null>): ToolbarAria {\n const {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n orientation = 'horizontal'\n } = props;\n let [isInToolbar, setInToolbar] = useState(false);\n // should be safe because re-calling set state with the same value it already has is a no-op\n // this will allow us to react should a parent re-render and change its role though\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(() => {\n setInToolbar(!!(ref.current && ref.current.parentElement?.closest('[role=\"toolbar\"]')));\n });\n const {direction} = useLocale();\n const shouldReverse = direction === 'rtl' && orientation === 'horizontal';\n let focusManager = createFocusManager(ref);\n\n const onKeyDown: KeyboardEventHandler = (e) => {\n // don't handle portalled events\n if (!nodeContains(e.currentTarget, e.target as HTMLElement)) {\n return;\n }\n if (\n (orientation === 'horizontal' && e.key === 'ArrowRight')\n || (orientation === 'vertical' && e.key === 'ArrowDown')) {\n if (shouldReverse) {\n focusManager.focusPrevious();\n } else {\n focusManager.focusNext();\n }\n } else if (\n (orientation === 'horizontal' && e.key === 'ArrowLeft')\n || (orientation === 'vertical' && e.key === 'ArrowUp')) {\n if (shouldReverse) {\n focusManager.focusNext();\n } else {\n focusManager.focusPrevious();\n }\n } else if (e.key === 'Tab') {\n // When the tab key is pressed, we want to move focus\n // out of the entire toolbar. To do this, move focus\n // to the first or last focusable child, and let the\n // browser handle the Tab key as usual from there.\n e.stopPropagation();\n lastFocused.current = document.activeElement as HTMLElement;\n if (e.shiftKey) {\n focusManager.focusFirst();\n } else {\n focusManager.focusLast();\n }\n return;\n } else {\n // if we didn't handle anything, return early so we don't preventDefault\n return;\n }\n\n // Prevent arrow keys from being handled by nested action groups.\n e.stopPropagation();\n e.preventDefault();\n };\n\n // Record the last focused child when focus moves out of the toolbar.\n const lastFocused = useRef<HTMLElement | null>(null);\n const onBlur = (e) => {\n if (!nodeContains(e.currentTarget, e.relatedTarget) && !lastFocused.current) {\n lastFocused.current = e.target;\n }\n };\n\n // Restore focus to the last focused child when focus returns into the toolbar.\n // If the element was removed, do nothing, either the first item in the first group,\n // or the last item in the last group will be focused, depending on direction.\n const onFocus = (e) => {\n if (lastFocused.current && !nodeContains(e.currentTarget, e.relatedTarget) && nodeContains(ref.current, e.target)) {\n lastFocused.current?.focus();\n lastFocused.current = null;\n }\n };\n\n return {\n toolbarProps: {\n ...filterDOMProps(props, {labelable: true}),\n role: !isInToolbar ? 'toolbar' : 'group',\n 'aria-orientation': orientation,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabel == null ? ariaLabelledBy : undefined,\n onKeyDownCapture: !isInToolbar ? onKeyDown : undefined,\n onFocusCapture: !isInToolbar ? onFocus : undefined,\n onBlurCapture: !isInToolbar ? onBlur : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useToolbar.main.js.map"}
@@ -1,91 +0,0 @@
1
- import {createFocusManager as $k3LOe$createFocusManager} from "@react-aria/focus";
2
- import {useLayoutEffect as $k3LOe$useLayoutEffect, nodeContains as $k3LOe$nodeContains, filterDOMProps as $k3LOe$filterDOMProps} from "@react-aria/utils";
3
- import {useState as $k3LOe$useState, useRef as $k3LOe$useRef} from "react";
4
- import {useLocale as $k3LOe$useLocale} from "@react-aria/i18n";
5
-
6
- /*
7
- * Copyright 2023 Adobe. All rights reserved.
8
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License. You may obtain a copy
10
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software distributed under
13
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
- * OF ANY KIND, either express or implied. See the License for the specific language
15
- * governing permissions and limitations under the License.
16
- */
17
-
18
-
19
-
20
- function $2680b1829e803644$export$fa142eb1681c520(props, ref) {
21
- const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, orientation: orientation = 'horizontal' } = props;
22
- let [isInToolbar, setInToolbar] = (0, $k3LOe$useState)(false);
23
- // should be safe because re-calling set state with the same value it already has is a no-op
24
- // this will allow us to react should a parent re-render and change its role though
25
- // eslint-disable-next-line react-hooks/exhaustive-deps
26
- (0, $k3LOe$useLayoutEffect)(()=>{
27
- var _ref_current_parentElement;
28
- setInToolbar(!!(ref.current && ((_ref_current_parentElement = ref.current.parentElement) === null || _ref_current_parentElement === void 0 ? void 0 : _ref_current_parentElement.closest('[role="toolbar"]'))));
29
- });
30
- const { direction: direction } = (0, $k3LOe$useLocale)();
31
- const shouldReverse = direction === 'rtl' && orientation === 'horizontal';
32
- let focusManager = (0, $k3LOe$createFocusManager)(ref);
33
- const onKeyDown = (e)=>{
34
- // don't handle portalled events
35
- if (!(0, $k3LOe$nodeContains)(e.currentTarget, e.target)) return;
36
- if (orientation === 'horizontal' && e.key === 'ArrowRight' || orientation === 'vertical' && e.key === 'ArrowDown') {
37
- if (shouldReverse) focusManager.focusPrevious();
38
- else focusManager.focusNext();
39
- } else if (orientation === 'horizontal' && e.key === 'ArrowLeft' || orientation === 'vertical' && e.key === 'ArrowUp') {
40
- if (shouldReverse) focusManager.focusNext();
41
- else focusManager.focusPrevious();
42
- } else if (e.key === 'Tab') {
43
- // When the tab key is pressed, we want to move focus
44
- // out of the entire toolbar. To do this, move focus
45
- // to the first or last focusable child, and let the
46
- // browser handle the Tab key as usual from there.
47
- e.stopPropagation();
48
- lastFocused.current = document.activeElement;
49
- if (e.shiftKey) focusManager.focusFirst();
50
- else focusManager.focusLast();
51
- return;
52
- } else // if we didn't handle anything, return early so we don't preventDefault
53
- return;
54
- // Prevent arrow keys from being handled by nested action groups.
55
- e.stopPropagation();
56
- e.preventDefault();
57
- };
58
- // Record the last focused child when focus moves out of the toolbar.
59
- const lastFocused = (0, $k3LOe$useRef)(null);
60
- const onBlur = (e)=>{
61
- if (!(0, $k3LOe$nodeContains)(e.currentTarget, e.relatedTarget) && !lastFocused.current) lastFocused.current = e.target;
62
- };
63
- // Restore focus to the last focused child when focus returns into the toolbar.
64
- // If the element was removed, do nothing, either the first item in the first group,
65
- // or the last item in the last group will be focused, depending on direction.
66
- const onFocus = (e)=>{
67
- if (lastFocused.current && !(0, $k3LOe$nodeContains)(e.currentTarget, e.relatedTarget) && (0, $k3LOe$nodeContains)(ref.current, e.target)) {
68
- var _lastFocused_current;
69
- (_lastFocused_current = lastFocused.current) === null || _lastFocused_current === void 0 ? void 0 : _lastFocused_current.focus();
70
- lastFocused.current = null;
71
- }
72
- };
73
- return {
74
- toolbarProps: {
75
- ...(0, $k3LOe$filterDOMProps)(props, {
76
- labelable: true
77
- }),
78
- role: !isInToolbar ? 'toolbar' : 'group',
79
- 'aria-orientation': orientation,
80
- 'aria-label': ariaLabel,
81
- 'aria-labelledby': ariaLabel == null ? ariaLabelledBy : undefined,
82
- onKeyDownCapture: !isInToolbar ? onKeyDown : undefined,
83
- onFocusCapture: !isInToolbar ? onFocus : undefined,
84
- onBlurCapture: !isInToolbar ? onBlur : undefined
85
- }
86
- };
87
- }
88
-
89
-
90
- export {$2680b1829e803644$export$fa142eb1681c520 as useToolbar};
91
- //# sourceMappingURL=useToolbar.module.js.map
@@ -1,91 +0,0 @@
1
- import {createFocusManager as $k3LOe$createFocusManager} from "@react-aria/focus";
2
- import {useLayoutEffect as $k3LOe$useLayoutEffect, nodeContains as $k3LOe$nodeContains, filterDOMProps as $k3LOe$filterDOMProps} from "@react-aria/utils";
3
- import {useState as $k3LOe$useState, useRef as $k3LOe$useRef} from "react";
4
- import {useLocale as $k3LOe$useLocale} from "@react-aria/i18n";
5
-
6
- /*
7
- * Copyright 2023 Adobe. All rights reserved.
8
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License. You may obtain a copy
10
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software distributed under
13
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
- * OF ANY KIND, either express or implied. See the License for the specific language
15
- * governing permissions and limitations under the License.
16
- */
17
-
18
-
19
-
20
- function $2680b1829e803644$export$fa142eb1681c520(props, ref) {
21
- const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, orientation: orientation = 'horizontal' } = props;
22
- let [isInToolbar, setInToolbar] = (0, $k3LOe$useState)(false);
23
- // should be safe because re-calling set state with the same value it already has is a no-op
24
- // this will allow us to react should a parent re-render and change its role though
25
- // eslint-disable-next-line react-hooks/exhaustive-deps
26
- (0, $k3LOe$useLayoutEffect)(()=>{
27
- var _ref_current_parentElement;
28
- setInToolbar(!!(ref.current && ((_ref_current_parentElement = ref.current.parentElement) === null || _ref_current_parentElement === void 0 ? void 0 : _ref_current_parentElement.closest('[role="toolbar"]'))));
29
- });
30
- const { direction: direction } = (0, $k3LOe$useLocale)();
31
- const shouldReverse = direction === 'rtl' && orientation === 'horizontal';
32
- let focusManager = (0, $k3LOe$createFocusManager)(ref);
33
- const onKeyDown = (e)=>{
34
- // don't handle portalled events
35
- if (!(0, $k3LOe$nodeContains)(e.currentTarget, e.target)) return;
36
- if (orientation === 'horizontal' && e.key === 'ArrowRight' || orientation === 'vertical' && e.key === 'ArrowDown') {
37
- if (shouldReverse) focusManager.focusPrevious();
38
- else focusManager.focusNext();
39
- } else if (orientation === 'horizontal' && e.key === 'ArrowLeft' || orientation === 'vertical' && e.key === 'ArrowUp') {
40
- if (shouldReverse) focusManager.focusNext();
41
- else focusManager.focusPrevious();
42
- } else if (e.key === 'Tab') {
43
- // When the tab key is pressed, we want to move focus
44
- // out of the entire toolbar. To do this, move focus
45
- // to the first or last focusable child, and let the
46
- // browser handle the Tab key as usual from there.
47
- e.stopPropagation();
48
- lastFocused.current = document.activeElement;
49
- if (e.shiftKey) focusManager.focusFirst();
50
- else focusManager.focusLast();
51
- return;
52
- } else // if we didn't handle anything, return early so we don't preventDefault
53
- return;
54
- // Prevent arrow keys from being handled by nested action groups.
55
- e.stopPropagation();
56
- e.preventDefault();
57
- };
58
- // Record the last focused child when focus moves out of the toolbar.
59
- const lastFocused = (0, $k3LOe$useRef)(null);
60
- const onBlur = (e)=>{
61
- if (!(0, $k3LOe$nodeContains)(e.currentTarget, e.relatedTarget) && !lastFocused.current) lastFocused.current = e.target;
62
- };
63
- // Restore focus to the last focused child when focus returns into the toolbar.
64
- // If the element was removed, do nothing, either the first item in the first group,
65
- // or the last item in the last group will be focused, depending on direction.
66
- const onFocus = (e)=>{
67
- if (lastFocused.current && !(0, $k3LOe$nodeContains)(e.currentTarget, e.relatedTarget) && (0, $k3LOe$nodeContains)(ref.current, e.target)) {
68
- var _lastFocused_current;
69
- (_lastFocused_current = lastFocused.current) === null || _lastFocused_current === void 0 ? void 0 : _lastFocused_current.focus();
70
- lastFocused.current = null;
71
- }
72
- };
73
- return {
74
- toolbarProps: {
75
- ...(0, $k3LOe$filterDOMProps)(props, {
76
- labelable: true
77
- }),
78
- role: !isInToolbar ? 'toolbar' : 'group',
79
- 'aria-orientation': orientation,
80
- 'aria-label': ariaLabel,
81
- 'aria-labelledby': ariaLabel == null ? ariaLabelledBy : undefined,
82
- onKeyDownCapture: !isInToolbar ? onKeyDown : undefined,
83
- onFocusCapture: !isInToolbar ? onFocus : undefined,
84
- onBlurCapture: !isInToolbar ? onBlur : undefined
85
- }
86
- };
87
- }
88
-
89
-
90
- export {$2680b1829e803644$export$fa142eb1681c520 as useToolbar};
91
- //# sourceMappingURL=useToolbar.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA6BM,SAAS,yCAAW,KAAuB,EAAE,GAAkC;IACpF,MAAM,EACJ,cAAc,SAAS,EACvB,mBAAmB,cAAc,eACjC,cAAc,cACf,GAAG;IACJ,IAAI,CAAC,aAAa,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC3C,4FAA4F;IAC5F,mFAAmF;IACnF,uDAAuD;IACvD,CAAA,GAAA,sBAAc,EAAE;YACiB;QAA/B,aAAa,CAAC,CAAE,CAAA,IAAI,OAAO,MAAI,6BAAA,IAAI,OAAO,CAAC,aAAa,cAAzB,iDAAA,2BAA2B,OAAO,CAAC,oBAAkB;IACtF;IACA,MAAM,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC5B,MAAM,gBAAgB,cAAc,SAAS,gBAAgB;IAC7D,IAAI,eAAe,CAAA,GAAA,yBAAiB,EAAE;IAEtC,MAAM,YAAkC,CAAC;QACvC,gCAAgC;QAChC,IAAI,CAAC,CAAA,GAAA,mBAAW,EAAE,EAAE,aAAa,EAAE,EAAE,MAAM,GACzC;QAEF,IACE,AAAC,gBAAgB,gBAAgB,EAAE,GAAG,KAAK,gBACvC,gBAAgB,cAAc,EAAE,GAAG,KAAK;YAC5C,IAAI,eACF,aAAa,aAAa;iBAE1B,aAAa,SAAS;eAEnB,IACL,AAAC,gBAAgB,gBAAgB,EAAE,GAAG,KAAK,eACvC,gBAAgB,cAAc,EAAE,GAAG,KAAK;YAC5C,IAAI,eACF,aAAa,SAAS;iBAEtB,aAAa,aAAa;eAEvB,IAAI,EAAE,GAAG,KAAK,OAAO;YAC1B,qDAAqD;YACrD,oDAAoD;YACpD,oDAAoD;YACpD,kDAAkD;YAClD,EAAE,eAAe;YACjB,YAAY,OAAO,GAAG,SAAS,aAAa;YAC5C,IAAI,EAAE,QAAQ,EACZ,aAAa,UAAU;iBAEvB,aAAa,SAAS;YAExB;QACF,OACE,wEAAwE;QACxE;QAGF,iEAAiE;QACjE,EAAE,eAAe;QACjB,EAAE,cAAc;IAClB;IAEA,qEAAqE;IACrE,MAAM,cAAc,CAAA,GAAA,aAAK,EAAsB;IAC/C,MAAM,SAAS,CAAC;QACd,IAAI,CAAC,CAAA,GAAA,mBAAW,EAAE,EAAE,aAAa,EAAE,EAAE,aAAa,KAAK,CAAC,YAAY,OAAO,EACzE,YAAY,OAAO,GAAG,EAAE,MAAM;IAElC;IAEA,+EAA+E;IAC/E,oFAAoF;IACpF,8EAA8E;IAC9E,MAAM,UAAU,CAAC;QACf,IAAI,YAAY,OAAO,IAAI,CAAC,CAAA,GAAA,mBAAW,EAAE,EAAE,aAAa,EAAE,EAAE,aAAa,KAAK,CAAA,GAAA,mBAAW,EAAE,IAAI,OAAO,EAAE,EAAE,MAAM,GAAG;gBACjH;aAAA,uBAAA,YAAY,OAAO,cAAnB,2CAAA,qBAAqB,KAAK;YAC1B,YAAY,OAAO,GAAG;QACxB;IACF;IAEA,OAAO;QACL,cAAc;YACZ,GAAG,CAAA,GAAA,qBAAa,EAAE,OAAO;gBAAC,WAAW;YAAI,EAAE;YAC3C,MAAM,CAAC,cAAc,YAAY;YACjC,oBAAoB;YACpB,cAAc;YACd,mBAAmB,aAAa,OAAO,iBAAiB;YACxD,kBAAkB,CAAC,cAAc,YAAY;YAC7C,gBAAgB,CAAC,cAAc,UAAU;YACzC,eAAe,CAAC,cAAc,SAAS;QACzC;IACF;AACF","sources":["packages/@react-aria/toolbar/src/useToolbar.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, Orientation, RefObject} from '@react-types/shared';\nimport {createFocusManager} from '@react-aria/focus';\nimport {filterDOMProps, nodeContains, useLayoutEffect} from '@react-aria/utils';\nimport {HTMLAttributes, KeyboardEventHandler, useRef, useState} from 'react';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaToolbarProps extends AriaLabelingProps {\n /**\n * The orientation of the entire toolbar.\n * @default 'horizontal'\n */\n orientation?: Orientation\n}\n\nexport interface ToolbarAria {\n /**\n * Props for the toolbar container.\n */\n toolbarProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toolbar.\n * A toolbar is a container for a set of interactive controls with arrow key navigation.\n * @param props - Props to be applied to the toolbar.\n * @param ref - A ref to a DOM element for the toolbar.\n */\nexport function useToolbar(props: AriaToolbarProps, ref: RefObject<HTMLElement | null>): ToolbarAria {\n const {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n orientation = 'horizontal'\n } = props;\n let [isInToolbar, setInToolbar] = useState(false);\n // should be safe because re-calling set state with the same value it already has is a no-op\n // this will allow us to react should a parent re-render and change its role though\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(() => {\n setInToolbar(!!(ref.current && ref.current.parentElement?.closest('[role=\"toolbar\"]')));\n });\n const {direction} = useLocale();\n const shouldReverse = direction === 'rtl' && orientation === 'horizontal';\n let focusManager = createFocusManager(ref);\n\n const onKeyDown: KeyboardEventHandler = (e) => {\n // don't handle portalled events\n if (!nodeContains(e.currentTarget, e.target as HTMLElement)) {\n return;\n }\n if (\n (orientation === 'horizontal' && e.key === 'ArrowRight')\n || (orientation === 'vertical' && e.key === 'ArrowDown')) {\n if (shouldReverse) {\n focusManager.focusPrevious();\n } else {\n focusManager.focusNext();\n }\n } else if (\n (orientation === 'horizontal' && e.key === 'ArrowLeft')\n || (orientation === 'vertical' && e.key === 'ArrowUp')) {\n if (shouldReverse) {\n focusManager.focusNext();\n } else {\n focusManager.focusPrevious();\n }\n } else if (e.key === 'Tab') {\n // When the tab key is pressed, we want to move focus\n // out of the entire toolbar. To do this, move focus\n // to the first or last focusable child, and let the\n // browser handle the Tab key as usual from there.\n e.stopPropagation();\n lastFocused.current = document.activeElement as HTMLElement;\n if (e.shiftKey) {\n focusManager.focusFirst();\n } else {\n focusManager.focusLast();\n }\n return;\n } else {\n // if we didn't handle anything, return early so we don't preventDefault\n return;\n }\n\n // Prevent arrow keys from being handled by nested action groups.\n e.stopPropagation();\n e.preventDefault();\n };\n\n // Record the last focused child when focus moves out of the toolbar.\n const lastFocused = useRef<HTMLElement | null>(null);\n const onBlur = (e) => {\n if (!nodeContains(e.currentTarget, e.relatedTarget) && !lastFocused.current) {\n lastFocused.current = e.target;\n }\n };\n\n // Restore focus to the last focused child when focus returns into the toolbar.\n // If the element was removed, do nothing, either the first item in the first group,\n // or the last item in the last group will be focused, depending on direction.\n const onFocus = (e) => {\n if (lastFocused.current && !nodeContains(e.currentTarget, e.relatedTarget) && nodeContains(ref.current, e.target)) {\n lastFocused.current?.focus();\n lastFocused.current = null;\n }\n };\n\n return {\n toolbarProps: {\n ...filterDOMProps(props, {labelable: true}),\n role: !isInToolbar ? 'toolbar' : 'group',\n 'aria-orientation': orientation,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabel == null ? ariaLabelledBy : undefined,\n onKeyDownCapture: !isInToolbar ? onKeyDown : undefined,\n onFocusCapture: !isInToolbar ? onFocus : undefined,\n onBlurCapture: !isInToolbar ? onBlur : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useToolbar.module.js.map"}
package/src/useToolbar.ts DELETED
@@ -1,131 +0,0 @@
1
- /*
2
- * Copyright 2023 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {AriaLabelingProps, Orientation, RefObject} from '@react-types/shared';
14
- import {createFocusManager} from '@react-aria/focus';
15
- import {filterDOMProps, nodeContains, useLayoutEffect} from '@react-aria/utils';
16
- import {HTMLAttributes, KeyboardEventHandler, useRef, useState} from 'react';
17
- import {useLocale} from '@react-aria/i18n';
18
-
19
- export interface AriaToolbarProps extends AriaLabelingProps {
20
- /**
21
- * The orientation of the entire toolbar.
22
- * @default 'horizontal'
23
- */
24
- orientation?: Orientation
25
- }
26
-
27
- export interface ToolbarAria {
28
- /**
29
- * Props for the toolbar container.
30
- */
31
- toolbarProps: HTMLAttributes<HTMLElement>
32
- }
33
-
34
- /**
35
- * Provides the behavior and accessibility implementation for a toolbar.
36
- * A toolbar is a container for a set of interactive controls with arrow key navigation.
37
- * @param props - Props to be applied to the toolbar.
38
- * @param ref - A ref to a DOM element for the toolbar.
39
- */
40
- export function useToolbar(props: AriaToolbarProps, ref: RefObject<HTMLElement | null>): ToolbarAria {
41
- const {
42
- 'aria-label': ariaLabel,
43
- 'aria-labelledby': ariaLabelledBy,
44
- orientation = 'horizontal'
45
- } = props;
46
- let [isInToolbar, setInToolbar] = useState(false);
47
- // should be safe because re-calling set state with the same value it already has is a no-op
48
- // this will allow us to react should a parent re-render and change its role though
49
- // eslint-disable-next-line react-hooks/exhaustive-deps
50
- useLayoutEffect(() => {
51
- setInToolbar(!!(ref.current && ref.current.parentElement?.closest('[role="toolbar"]')));
52
- });
53
- const {direction} = useLocale();
54
- const shouldReverse = direction === 'rtl' && orientation === 'horizontal';
55
- let focusManager = createFocusManager(ref);
56
-
57
- const onKeyDown: KeyboardEventHandler = (e) => {
58
- // don't handle portalled events
59
- if (!nodeContains(e.currentTarget, e.target as HTMLElement)) {
60
- return;
61
- }
62
- if (
63
- (orientation === 'horizontal' && e.key === 'ArrowRight')
64
- || (orientation === 'vertical' && e.key === 'ArrowDown')) {
65
- if (shouldReverse) {
66
- focusManager.focusPrevious();
67
- } else {
68
- focusManager.focusNext();
69
- }
70
- } else if (
71
- (orientation === 'horizontal' && e.key === 'ArrowLeft')
72
- || (orientation === 'vertical' && e.key === 'ArrowUp')) {
73
- if (shouldReverse) {
74
- focusManager.focusNext();
75
- } else {
76
- focusManager.focusPrevious();
77
- }
78
- } else if (e.key === 'Tab') {
79
- // When the tab key is pressed, we want to move focus
80
- // out of the entire toolbar. To do this, move focus
81
- // to the first or last focusable child, and let the
82
- // browser handle the Tab key as usual from there.
83
- e.stopPropagation();
84
- lastFocused.current = document.activeElement as HTMLElement;
85
- if (e.shiftKey) {
86
- focusManager.focusFirst();
87
- } else {
88
- focusManager.focusLast();
89
- }
90
- return;
91
- } else {
92
- // if we didn't handle anything, return early so we don't preventDefault
93
- return;
94
- }
95
-
96
- // Prevent arrow keys from being handled by nested action groups.
97
- e.stopPropagation();
98
- e.preventDefault();
99
- };
100
-
101
- // Record the last focused child when focus moves out of the toolbar.
102
- const lastFocused = useRef<HTMLElement | null>(null);
103
- const onBlur = (e) => {
104
- if (!nodeContains(e.currentTarget, e.relatedTarget) && !lastFocused.current) {
105
- lastFocused.current = e.target;
106
- }
107
- };
108
-
109
- // Restore focus to the last focused child when focus returns into the toolbar.
110
- // If the element was removed, do nothing, either the first item in the first group,
111
- // or the last item in the last group will be focused, depending on direction.
112
- const onFocus = (e) => {
113
- if (lastFocused.current && !nodeContains(e.currentTarget, e.relatedTarget) && nodeContains(ref.current, e.target)) {
114
- lastFocused.current?.focus();
115
- lastFocused.current = null;
116
- }
117
- };
118
-
119
- return {
120
- toolbarProps: {
121
- ...filterDOMProps(props, {labelable: true}),
122
- role: !isInToolbar ? 'toolbar' : 'group',
123
- 'aria-orientation': orientation,
124
- 'aria-label': ariaLabel,
125
- 'aria-labelledby': ariaLabel == null ? ariaLabelledBy : undefined,
126
- onKeyDownCapture: !isInToolbar ? onKeyDown : undefined,
127
- onFocusCapture: !isInToolbar ? onFocus : undefined,
128
- onBlurCapture: !isInToolbar ? onBlur : undefined
129
- }
130
- };
131
- }