@elliemae/ds-toolbar 3.0.4-rc.4 → 3.0.4-rc.5

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.
@@ -61,12 +61,12 @@ var React = __toESM(require("react"));
61
61
  var import_react = __toESM(require("react"));
62
62
  var import_react_desc = require("react-desc");
63
63
  var import_ds_classnames = require("@elliemae/ds-classnames");
64
- var import_ds_shared = require("@elliemae/ds-shared");
65
64
  var import_ds_utilities = require("@elliemae/ds-utilities");
66
65
  var import_decorateToolbarChildren = __toESM(require("./decorateToolbarChildren"));
67
66
  var import_ToolbarItem = __toESM(require("./ToolbarItem"));
68
67
  var import_ToolbarGroup = __toESM(require("./ToolbarGroup"));
69
68
  var import_ToolbarDivider = __toESM(require("./ToolbarDivider"));
69
+ var import_useKeyboardNavigation = require("./hooks/useKeyboardNavigation");
70
70
  const blockName = "toolbar";
71
71
  const ToolbarContainer = (0, import_ds_classnames.aggregatedClasses)("div")(blockName, null, ({ withDepth, alignment, size }) => ({
72
72
  "without-depth": !withDepth,
@@ -92,17 +92,12 @@ const DSToolbar = (_a) => {
92
92
  "size"
93
93
  ]);
94
94
  const containerRef = (0, import_react.useRef)(null);
95
- return /* @__PURE__ */ import_react.default.createElement(import_ds_shared.FocusGroupProvider, {
96
- autoFocusOnMount,
97
- getContainer: () => containerRef.current,
98
- keyBindings: {
99
- Tab: "next"
100
- },
101
- orientation: "horizontal"
102
- }, /* @__PURE__ */ import_react.default.createElement(ToolbarContainer, __spreadProps(__spreadValues(__spreadValues({}, containerProps), otherProps), {
95
+ const { handleOnKeyDown } = (0, import_useKeyboardNavigation.useKeyboardNavigation)({ containerRef, autoFocusOnMount });
96
+ return /* @__PURE__ */ import_react.default.createElement(ToolbarContainer, __spreadProps(__spreadValues(__spreadValues({}, containerProps), otherProps), {
103
97
  classProps: { withDepth, alignment, size },
104
- innerRef: (0, import_ds_utilities.mergeRefs)(innerRef, containerRef)
105
- }), (0, import_decorateToolbarChildren.default)(children)));
98
+ innerRef: (0, import_ds_utilities.mergeRefs)(innerRef, containerRef),
99
+ onKeyDown: handleOnKeyDown
100
+ }), (0, import_decorateToolbarChildren.default)(children));
106
101
  };
107
102
  const toolbarProps = {
108
103
  containerProps: import_react_desc.PropTypes.object.description("Set of Properties attached to the main container"),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/deprecated/DSToolbar.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["import React, { useRef } from 'react';\nimport { describe, PropTypes } from 'react-desc';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport { FocusGroupProvider } from '@elliemae/ds-shared';\nimport { mergeRefs } from '@elliemae/ds-utilities';\nimport decorateToolbarChildren from './decorateToolbarChildren';\nimport Item from './ToolbarItem';\nimport ToolbarGroup from './ToolbarGroup';\nimport Divider from './ToolbarDivider';\n\nconst blockName = 'toolbar';\n\nconst ToolbarContainer = aggregatedClasses('div')(blockName, null, ({ withDepth, alignment, size }) => ({\n 'without-depth': !withDepth,\n [alignment]: !!alignment,\n [size]: size,\n}));\n\nconst DSToolbar = ({\n containerProps = {},\n innerRef,\n withDepth = true,\n alignment = 'right', // left || right\n autoFocusOnMount = true,\n children = [],\n size = 'normal',\n ...otherProps\n}) => {\n const containerRef = useRef(null);\n return (\n <FocusGroupProvider\n autoFocusOnMount={autoFocusOnMount}\n getContainer={() => containerRef.current}\n keyBindings={{\n Tab: 'next',\n }}\n orientation=\"horizontal\"\n >\n <ToolbarContainer\n {...containerProps}\n {...otherProps}\n classProps={{ withDepth, alignment, size }}\n innerRef={mergeRefs(innerRef, containerRef)}\n >\n {decorateToolbarChildren(children)}\n </ToolbarContainer>\n </FocusGroupProvider>\n );\n};\n\nconst toolbarProps = {\n containerProps: PropTypes.object.description('Set of Properties attached to the main container'),\n withDepth: PropTypes.bool.description('Shows a shadow rear the toolbar').defaultValue(true),\n alignment: PropTypes.oneOf(['right', 'left'])\n .description('Aligns the toolbar to the left or right')\n .defaultValue('right'),\n size: PropTypes.oneOf(['normal', 'compact']).description('Toolbar size').defaultValue('normal'),\n autoFocusOnMount: PropTypes.bool\n .description('Wheter to focus the component when it mounts or not')\n .defaultValue(true),\n children: PropTypes.oneOfType([PropTypes.array, PropTypes.func, PropTypes.node]).description('Toolbar items')\n .isRequired,\n innerRef: PropTypes.object.description('Ref to the Toolbar container element'),\n};\n\nDSToolbar.propTypes = toolbarProps;\nDSToolbar.displayName = 'DSToolbar';\nconst ToolbarWithSchema = describe(DSToolbar);\nToolbarWithSchema.propTypes = toolbarProps;\n\nexport { DSToolbar, Item as ToolbarItem, ToolbarGroup, Divider as ToolbarDivider, ToolbarWithSchema };\n\nexport default DSToolbar;\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAA8B;AAC9B,wBAAoC;AACpC,2BAAkC;AAClC,uBAAmC;AACnC,0BAA0B;AAC1B,qCAAoC;AACpC,yBAAiB;AACjB,0BAAyB;AACzB,4BAAoB;AAEpB,MAAM,YAAY;AAElB,MAAM,mBAAmB,4CAAkB,KAAK,EAAE,WAAW,MAAM,CAAC,EAAE,WAAW,WAAW,WAAY;AAAA,EACtG,iBAAiB,CAAC;AAAA,GACjB,YAAY,CAAC,CAAC;AAAA,GACd,OAAO;AACV,EAAE;AAEF,MAAM,YAAY,CAAC,OASb;AATa,eACjB;AAAA,qBAAiB,CAAC;AAAA,IAClB;AAAA,IACA,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,mBAAmB;AAAA,IACnB,WAAW,CAAC;AAAA,IACZ,OAAO;AAAA,MAPU,IAQd,uBARc,IAQd;AAAA,IAPH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAGA,QAAM,eAAe,yBAAO,IAAI;AAChC,SACE,mDAAC;AAAA,IACC;AAAA,IACA,cAAc,MAAM,aAAa;AAAA,IACjC,aAAa;AAAA,MACX,KAAK;AAAA,IACP;AAAA,IACA,aAAY;AAAA,KAEZ,mDAAC,kEACK,iBACA,aAFL;AAAA,IAGC,YAAY,EAAE,WAAW,WAAW,KAAK;AAAA,IACzC,UAAU,mCAAU,UAAU,YAAY;AAAA,MAEzC,4CAAwB,QAAQ,CACnC,CACF;AAEJ;AAEA,MAAM,eAAe;AAAA,EACnB,gBAAgB,4BAAU,OAAO,YAAY,kDAAkD;AAAA,EAC/F,WAAW,4BAAU,KAAK,YAAY,iCAAiC,EAAE,aAAa,IAAI;AAAA,EAC1F,WAAW,4BAAU,MAAM,CAAC,SAAS,MAAM,CAAC,EACzC,YAAY,yCAAyC,EACrD,aAAa,OAAO;AAAA,EACvB,MAAM,4BAAU,MAAM,CAAC,UAAU,SAAS,CAAC,EAAE,YAAY,cAAc,EAAE,aAAa,QAAQ;AAAA,EAC9F,kBAAkB,4BAAU,KACzB,YAAY,qDAAqD,EACjE,aAAa,IAAI;AAAA,EACpB,UAAU,4BAAU,UAAU,CAAC,4BAAU,OAAO,4BAAU,MAAM,4BAAU,IAAI,CAAC,EAAE,YAAY,eAAe,EACzG;AAAA,EACH,UAAU,4BAAU,OAAO,YAAY,sCAAsC;AAC/E;AAEA,UAAU,YAAY;AACtB,UAAU,cAAc;AACxB,MAAM,oBAAoB,gCAAS,SAAS;AAC5C,kBAAkB,YAAY;AAI9B,IAAO,oBAAQ;",
4
+ "sourcesContent": ["import React, { useRef } from 'react';\nimport { describe, PropTypes } from 'react-desc';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport { mergeRefs } from '@elliemae/ds-utilities';\nimport decorateToolbarChildren from './decorateToolbarChildren';\nimport Item from './ToolbarItem';\nimport ToolbarGroup from './ToolbarGroup';\nimport Divider from './ToolbarDivider';\nimport { useKeyboardNavigation } from './hooks/useKeyboardNavigation';\n\nconst blockName = 'toolbar';\n\nconst ToolbarContainer = aggregatedClasses('div')(blockName, null, ({ withDepth, alignment, size }) => ({\n 'without-depth': !withDepth,\n [alignment]: !!alignment,\n [size]: size,\n}));\n\nconst DSToolbar = ({\n containerProps = {},\n innerRef,\n withDepth = true,\n alignment = 'right', // left || right\n autoFocusOnMount = true,\n children = [],\n size = 'normal',\n ...otherProps\n}) => {\n const containerRef = useRef<HTMLDivElement | null>(null);\n\n const { handleOnKeyDown } = useKeyboardNavigation({ containerRef, autoFocusOnMount });\n\n return (\n <ToolbarContainer\n {...containerProps}\n {...otherProps}\n classProps={{ withDepth, alignment, size }}\n innerRef={mergeRefs(innerRef, containerRef)}\n onKeyDown={handleOnKeyDown}\n >\n {decorateToolbarChildren(children)}\n </ToolbarContainer>\n );\n};\n\nconst toolbarProps = {\n containerProps: PropTypes.object.description('Set of Properties attached to the main container'),\n withDepth: PropTypes.bool.description('Shows a shadow rear the toolbar').defaultValue(true),\n alignment: PropTypes.oneOf(['right', 'left'])\n .description('Aligns the toolbar to the left or right')\n .defaultValue('right'),\n size: PropTypes.oneOf(['normal', 'compact']).description('Toolbar size').defaultValue('normal'),\n autoFocusOnMount: PropTypes.bool\n .description('Wheter to focus the component when it mounts or not')\n .defaultValue(true),\n children: PropTypes.oneOfType([PropTypes.array, PropTypes.func, PropTypes.node]).description('Toolbar items')\n .isRequired,\n innerRef: PropTypes.object.description('Ref to the Toolbar container element'),\n};\n\nDSToolbar.propTypes = toolbarProps;\nDSToolbar.displayName = 'DSToolbar';\nconst ToolbarWithSchema = describe(DSToolbar);\nToolbarWithSchema.propTypes = toolbarProps;\n\nexport { DSToolbar, Item as ToolbarItem, ToolbarGroup, Divider as ToolbarDivider, ToolbarWithSchema };\n\nexport default DSToolbar;\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AA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,EAAE,aAAa,QAAQ;AAAA,EAC9F,kBAAkB,4BAAU,KACzB,YAAY,qDAAqD,EACjE,aAAa,IAAI;AAAA,EACpB,UAAU,4BAAU,UAAU,CAAC,4BAAU,OAAO,4BAAU,MAAM,4BAAU,IAAI,CAAC,EAAE,YAAY,eAAe,EACzG;AAAA,EACH,UAAU,4BAAU,OAAO,YAAY,sCAAsC;AAC/E;AAEA,UAAU,YAAY;AACtB,UAAU,cAAc;AACxB,MAAM,oBAAoB,gCAAS,SAAS;AAC5C,kBAAkB,YAAY;AAI9B,IAAO,oBAAQ;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,64 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var useKeyboardNavigation_exports = {};
22
+ __export(useKeyboardNavigation_exports, {
23
+ useKeyboardNavigation: () => useKeyboardNavigation
24
+ });
25
+ module.exports = __toCommonJS(useKeyboardNavigation_exports);
26
+ var React = __toESM(require("react"));
27
+ var import_react = require("react");
28
+ const useKeyboardNavigation = ({ containerRef, autoFocusOnMount }) => {
29
+ const allChildrenButtonRef = (0, import_react.useRef)(null);
30
+ (0, import_react.useEffect)(() => {
31
+ if (containerRef.current) {
32
+ allChildrenButtonRef.current = containerRef.current.querySelectorAll("button");
33
+ }
34
+ if (autoFocusOnMount) {
35
+ setTimeout(() => allChildrenButtonRef.current?.[0].focus());
36
+ }
37
+ }, [autoFocusOnMount]);
38
+ const handleOnKeyDown = (0, import_react.useCallback)((e) => {
39
+ if (allChildrenButtonRef.current) {
40
+ const lastButton = allChildrenButtonRef.current[allChildrenButtonRef.current?.length - 1];
41
+ const firstButton = allChildrenButtonRef.current[0];
42
+ if (e.key === "ArrowRight") {
43
+ e.preventDefault();
44
+ if (e.target !== lastButton) {
45
+ e.target.nextSibling.focus();
46
+ } else {
47
+ firstButton.focus();
48
+ }
49
+ }
50
+ if (e.key === "ArrowLeft") {
51
+ e.preventDefault();
52
+ if (e.target !== firstButton) {
53
+ e.target.previousSibling.focus();
54
+ } else {
55
+ lastButton.focus();
56
+ }
57
+ }
58
+ }
59
+ }, []);
60
+ return {
61
+ handleOnKeyDown
62
+ };
63
+ };
64
+ //# sourceMappingURL=useKeyboardNavigation.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/deprecated/hooks/useKeyboardNavigation.tsx", "../../../../../../scripts/build/transpile/react-shim.js"],
4
+ "sourcesContent": ["import React, { useRef, useEffect, useCallback } from 'react';\n\ninterface useKeyboardNavigationT {\n containerRef: React.MutableRefObject<HTMLDivElement | null>;\n autoFocusOnMount: boolean;\n}\n\n// Toolbar should not allow to use Tab/Shift+Tab to navigate between ToolbarItems.\n// Tab/Shift+Tab should be only used once to enter the whole controller.\n// Toolbars should be only navigable with Arrows to follow correct a11y.\n// https://www.w3.org/TR/wai-aria-practices/examples/toolbar/toolbar.html\n\nexport const useKeyboardNavigation = ({ containerRef, autoFocusOnMount }: useKeyboardNavigationT) => {\n const allChildrenButtonRef = useRef<NodeListOf<HTMLButtonElement> | null>(null);\n\n useEffect(() => {\n if (containerRef.current) {\n allChildrenButtonRef.current = containerRef.current.querySelectorAll('button');\n // allChildrenButtonRef.current.forEach((button, index) => {\n // if (index !== 0) {\n // button.setAttribute('tabindex', '-1');\n // }\n // });\n }\n\n if (autoFocusOnMount) {\n setTimeout(() => allChildrenButtonRef.current?.[0].focus());\n }\n\n // return () => {\n // allChildrenButtonRef.current?.forEach((button, index) => {\n // if (index !== 0) {\n // button.setAttribute('tabindex', '');\n // }\n // });\n // };\n }, [autoFocusOnMount]);\n\n const handleOnKeyDown = useCallback((e) => {\n if (allChildrenButtonRef.current) {\n const lastButton = allChildrenButtonRef.current[allChildrenButtonRef.current?.length - 1];\n const firstButton = allChildrenButtonRef.current[0];\n\n if (e.key === 'ArrowRight') {\n e.preventDefault();\n if (e.target !== lastButton) {\n e.target.nextSibling.focus();\n } else {\n firstButton.focus();\n }\n }\n if (e.key === 'ArrowLeft') {\n e.preventDefault();\n if (e.target !== firstButton) {\n e.target.previousSibling.focus();\n } else {\n lastButton.focus();\n }\n }\n }\n }, []);\n\n return {\n handleOnKeyDown,\n };\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAsD;AAY/C,MAAM,wBAAwB,CAAC,EAAE,cAAc,uBAA+C;AACnG,QAAM,uBAAuB,yBAA6C,IAAI;AAE9E,8BAAU,MAAM;AACd,QAAI,aAAa,SAAS;AACxB,2BAAqB,UAAU,aAAa,QAAQ,iBAAiB,QAAQ;AAAA,IAM/E;AAEA,QAAI,kBAAkB;AACpB,iBAAW,MAAM,qBAAqB,UAAU,GAAG,MAAM,CAAC;AAAA,IAC5D;AAAA,EASF,GAAG,CAAC,gBAAgB,CAAC;AAErB,QAAM,kBAAkB,8BAAY,CAAC,MAAM;AACzC,QAAI,qBAAqB,SAAS;AAChC,YAAM,aAAa,qBAAqB,QAAQ,qBAAqB,SAAS,SAAS;AACvF,YAAM,cAAc,qBAAqB,QAAQ;AAEjD,UAAI,EAAE,QAAQ,cAAc;AAC1B,UAAE,eAAe;AACjB,YAAI,EAAE,WAAW,YAAY;AAC3B,YAAE,OAAO,YAAY,MAAM;AAAA,QAC7B,OAAO;AACL,sBAAY,MAAM;AAAA,QACpB;AAAA,MACF;AACA,UAAI,EAAE,QAAQ,aAAa;AACzB,UAAE,eAAe;AACjB,YAAI,EAAE,WAAW,aAAa;AAC5B,YAAE,OAAO,gBAAgB,MAAM;AAAA,QACjC,OAAO;AACL,qBAAW,MAAM;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -33,12 +33,12 @@ import * as React from "react";
33
33
  import React2, { useRef } from "react";
34
34
  import { describe, PropTypes } from "react-desc";
35
35
  import { aggregatedClasses } from "@elliemae/ds-classnames";
36
- import { FocusGroupProvider } from "@elliemae/ds-shared";
37
36
  import { mergeRefs } from "@elliemae/ds-utilities";
38
37
  import decorateToolbarChildren from "./decorateToolbarChildren";
39
38
  import Item from "./ToolbarItem";
40
39
  import ToolbarGroup from "./ToolbarGroup";
41
40
  import Divider from "./ToolbarDivider";
41
+ import { useKeyboardNavigation } from "./hooks/useKeyboardNavigation";
42
42
  const blockName = "toolbar";
43
43
  const ToolbarContainer = aggregatedClasses("div")(blockName, null, ({ withDepth, alignment, size }) => ({
44
44
  "without-depth": !withDepth,
@@ -64,17 +64,12 @@ const DSToolbar = (_a) => {
64
64
  "size"
65
65
  ]);
66
66
  const containerRef = useRef(null);
67
- return /* @__PURE__ */ React2.createElement(FocusGroupProvider, {
68
- autoFocusOnMount,
69
- getContainer: () => containerRef.current,
70
- keyBindings: {
71
- Tab: "next"
72
- },
73
- orientation: "horizontal"
74
- }, /* @__PURE__ */ React2.createElement(ToolbarContainer, __spreadProps(__spreadValues(__spreadValues({}, containerProps), otherProps), {
67
+ const { handleOnKeyDown } = useKeyboardNavigation({ containerRef, autoFocusOnMount });
68
+ return /* @__PURE__ */ React2.createElement(ToolbarContainer, __spreadProps(__spreadValues(__spreadValues({}, containerProps), otherProps), {
75
69
  classProps: { withDepth, alignment, size },
76
- innerRef: mergeRefs(innerRef, containerRef)
77
- }), decorateToolbarChildren(children)));
70
+ innerRef: mergeRefs(innerRef, containerRef),
71
+ onKeyDown: handleOnKeyDown
72
+ }), decorateToolbarChildren(children));
78
73
  };
79
74
  const toolbarProps = {
80
75
  containerProps: PropTypes.object.description("Set of Properties attached to the main container"),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/deprecated/DSToolbar.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useRef } from 'react';\nimport { describe, PropTypes } from 'react-desc';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport { FocusGroupProvider } from '@elliemae/ds-shared';\nimport { mergeRefs } from '@elliemae/ds-utilities';\nimport decorateToolbarChildren from './decorateToolbarChildren';\nimport Item from './ToolbarItem';\nimport ToolbarGroup from './ToolbarGroup';\nimport Divider from './ToolbarDivider';\n\nconst blockName = 'toolbar';\n\nconst ToolbarContainer = aggregatedClasses('div')(blockName, null, ({ withDepth, alignment, size }) => ({\n 'without-depth': !withDepth,\n [alignment]: !!alignment,\n [size]: size,\n}));\n\nconst DSToolbar = ({\n containerProps = {},\n innerRef,\n withDepth = true,\n alignment = 'right', // left || right\n autoFocusOnMount = true,\n children = [],\n size = 'normal',\n ...otherProps\n}) => {\n const containerRef = useRef(null);\n return (\n <FocusGroupProvider\n autoFocusOnMount={autoFocusOnMount}\n getContainer={() => containerRef.current}\n keyBindings={{\n Tab: 'next',\n }}\n orientation=\"horizontal\"\n >\n <ToolbarContainer\n {...containerProps}\n {...otherProps}\n classProps={{ withDepth, alignment, size }}\n innerRef={mergeRefs(innerRef, containerRef)}\n >\n {decorateToolbarChildren(children)}\n </ToolbarContainer>\n </FocusGroupProvider>\n );\n};\n\nconst toolbarProps = {\n containerProps: PropTypes.object.description('Set of Properties attached to the main container'),\n withDepth: PropTypes.bool.description('Shows a shadow rear the toolbar').defaultValue(true),\n alignment: PropTypes.oneOf(['right', 'left'])\n .description('Aligns the toolbar to the left or right')\n .defaultValue('right'),\n size: PropTypes.oneOf(['normal', 'compact']).description('Toolbar size').defaultValue('normal'),\n autoFocusOnMount: PropTypes.bool\n .description('Wheter to focus the component when it mounts or not')\n .defaultValue(true),\n children: PropTypes.oneOfType([PropTypes.array, PropTypes.func, PropTypes.node]).description('Toolbar items')\n .isRequired,\n innerRef: PropTypes.object.description('Ref to the Toolbar container element'),\n};\n\nDSToolbar.propTypes = toolbarProps;\nDSToolbar.displayName = 'DSToolbar';\nconst ToolbarWithSchema = describe(DSToolbar);\nToolbarWithSchema.propTypes = toolbarProps;\n\nexport { DSToolbar, Item as ToolbarItem, ToolbarGroup, Divider as ToolbarDivider, ToolbarWithSchema };\n\nexport default DSToolbar;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAM,YAAY;AAElB,MAAM,mBAAmB,kBAAkB,KAAK,EAAE,WAAW,MAAM,CAAC,EAAE,WAAW,WAAW,WAAY;AAAA,EACtG,iBAAiB,CAAC;AAAA,GACjB,YAAY,CAAC,CAAC;AAAA,GACd,OAAO;AACV,EAAE;AAEF,MAAM,YAAY,CAAC,OASb;AATa,eACjB;AAAA,qBAAiB,CAAC;AAAA,IAClB;AAAA,IACA,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,mBAAmB;AAAA,IACnB,WAAW,CAAC;AAAA,IACZ,OAAO;AAAA,MAPU,IAQd,uBARc,IAQd;AAAA,IAPH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAGA,QAAM,eAAe,OAAO,IAAI;AAChC,SACE,qCAAC;AAAA,IACC;AAAA,IACA,cAAc,MAAM,aAAa;AAAA,IACjC,aAAa;AAAA,MACX,KAAK;AAAA,IACP;AAAA,IACA,aAAY;AAAA,KAEZ,qCAAC,kEACK,iBACA,aAFL;AAAA,IAGC,YAAY,EAAE,WAAW,WAAW,KAAK;AAAA,IACzC,UAAU,UAAU,UAAU,YAAY;AAAA,MAEzC,wBAAwB,QAAQ,CACnC,CACF;AAEJ;AAEA,MAAM,eAAe;AAAA,EACnB,gBAAgB,UAAU,OAAO,YAAY,kDAAkD;AAAA,EAC/F,WAAW,UAAU,KAAK,YAAY,iCAAiC,EAAE,aAAa,IAAI;AAAA,EAC1F,WAAW,UAAU,MAAM,CAAC,SAAS,MAAM,CAAC,EACzC,YAAY,yCAAyC,EACrD,aAAa,OAAO;AAAA,EACvB,MAAM,UAAU,MAAM,CAAC,UAAU,SAAS,CAAC,EAAE,YAAY,cAAc,EAAE,aAAa,QAAQ;AAAA,EAC9F,kBAAkB,UAAU,KACzB,YAAY,qDAAqD,EACjE,aAAa,IAAI;AAAA,EACpB,UAAU,UAAU,UAAU,CAAC,UAAU,OAAO,UAAU,MAAM,UAAU,IAAI,CAAC,EAAE,YAAY,eAAe,EACzG;AAAA,EACH,UAAU,UAAU,OAAO,YAAY,sCAAsC;AAC/E;AAEA,UAAU,YAAY;AACtB,UAAU,cAAc;AACxB,MAAM,oBAAoB,SAAS,SAAS;AAC5C,kBAAkB,YAAY;AAI9B,IAAO,oBAAQ;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useRef } from 'react';\nimport { describe, PropTypes } from 'react-desc';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport { mergeRefs } from '@elliemae/ds-utilities';\nimport decorateToolbarChildren from './decorateToolbarChildren';\nimport Item from './ToolbarItem';\nimport ToolbarGroup from './ToolbarGroup';\nimport Divider from './ToolbarDivider';\nimport { useKeyboardNavigation } from './hooks/useKeyboardNavigation';\n\nconst blockName = 'toolbar';\n\nconst ToolbarContainer = aggregatedClasses('div')(blockName, null, ({ withDepth, alignment, size }) => ({\n 'without-depth': !withDepth,\n [alignment]: !!alignment,\n [size]: size,\n}));\n\nconst DSToolbar = ({\n containerProps = {},\n innerRef,\n withDepth = true,\n alignment = 'right', // left || right\n autoFocusOnMount = true,\n children = [],\n size = 'normal',\n ...otherProps\n}) => {\n const containerRef = useRef<HTMLDivElement | null>(null);\n\n const { handleOnKeyDown } = useKeyboardNavigation({ containerRef, autoFocusOnMount });\n\n return (\n <ToolbarContainer\n {...containerProps}\n {...otherProps}\n classProps={{ withDepth, alignment, size }}\n innerRef={mergeRefs(innerRef, containerRef)}\n onKeyDown={handleOnKeyDown}\n >\n {decorateToolbarChildren(children)}\n </ToolbarContainer>\n );\n};\n\nconst toolbarProps = {\n containerProps: PropTypes.object.description('Set of Properties attached to the main container'),\n withDepth: PropTypes.bool.description('Shows a shadow rear the toolbar').defaultValue(true),\n alignment: PropTypes.oneOf(['right', 'left'])\n .description('Aligns the toolbar to the left or right')\n .defaultValue('right'),\n size: PropTypes.oneOf(['normal', 'compact']).description('Toolbar size').defaultValue('normal'),\n autoFocusOnMount: PropTypes.bool\n .description('Wheter to focus the component when it mounts or not')\n .defaultValue(true),\n children: PropTypes.oneOfType([PropTypes.array, PropTypes.func, PropTypes.node]).description('Toolbar items')\n .isRequired,\n innerRef: PropTypes.object.description('Ref to the Toolbar container element'),\n};\n\nDSToolbar.propTypes = toolbarProps;\nDSToolbar.displayName = 'DSToolbar';\nconst ToolbarWithSchema = describe(DSToolbar);\nToolbarWithSchema.propTypes = toolbarProps;\n\nexport { DSToolbar, Item as ToolbarItem, ToolbarGroup, Divider as ToolbarDivider, ToolbarWithSchema };\n\nexport default DSToolbar;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;ACA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AAC,EAAE,YAAY,eAAe,EACzG;AAAA,EACH,UAAU,UAAU,OAAO,YAAY,sCAAsC;AAC/E;AAEA,UAAU,YAAY;AACtB,UAAU,cAAc;AACxB,MAAM,oBAAoB,SAAS,SAAS;AAC5C,kBAAkB,YAAY;AAI9B,IAAO,oBAAQ;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,42 @@
1
+ import * as React from "react";
2
+ import { useRef, useEffect, useCallback } from "react";
3
+ const useKeyboardNavigation = ({ containerRef, autoFocusOnMount }) => {
4
+ const allChildrenButtonRef = useRef(null);
5
+ useEffect(() => {
6
+ if (containerRef.current) {
7
+ allChildrenButtonRef.current = containerRef.current.querySelectorAll("button");
8
+ }
9
+ if (autoFocusOnMount) {
10
+ setTimeout(() => allChildrenButtonRef.current?.[0].focus());
11
+ }
12
+ }, [autoFocusOnMount]);
13
+ const handleOnKeyDown = useCallback((e) => {
14
+ if (allChildrenButtonRef.current) {
15
+ const lastButton = allChildrenButtonRef.current[allChildrenButtonRef.current?.length - 1];
16
+ const firstButton = allChildrenButtonRef.current[0];
17
+ if (e.key === "ArrowRight") {
18
+ e.preventDefault();
19
+ if (e.target !== lastButton) {
20
+ e.target.nextSibling.focus();
21
+ } else {
22
+ firstButton.focus();
23
+ }
24
+ }
25
+ if (e.key === "ArrowLeft") {
26
+ e.preventDefault();
27
+ if (e.target !== firstButton) {
28
+ e.target.previousSibling.focus();
29
+ } else {
30
+ lastButton.focus();
31
+ }
32
+ }
33
+ }
34
+ }, []);
35
+ return {
36
+ handleOnKeyDown
37
+ };
38
+ };
39
+ export {
40
+ useKeyboardNavigation
41
+ };
42
+ //# sourceMappingURL=useKeyboardNavigation.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/deprecated/hooks/useKeyboardNavigation.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useRef, useEffect, useCallback } from 'react';\n\ninterface useKeyboardNavigationT {\n containerRef: React.MutableRefObject<HTMLDivElement | null>;\n autoFocusOnMount: boolean;\n}\n\n// Toolbar should not allow to use Tab/Shift+Tab to navigate between ToolbarItems.\n// Tab/Shift+Tab should be only used once to enter the whole controller.\n// Toolbars should be only navigable with Arrows to follow correct a11y.\n// https://www.w3.org/TR/wai-aria-practices/examples/toolbar/toolbar.html\n\nexport const useKeyboardNavigation = ({ containerRef, autoFocusOnMount }: useKeyboardNavigationT) => {\n const allChildrenButtonRef = useRef<NodeListOf<HTMLButtonElement> | null>(null);\n\n useEffect(() => {\n if (containerRef.current) {\n allChildrenButtonRef.current = containerRef.current.querySelectorAll('button');\n // allChildrenButtonRef.current.forEach((button, index) => {\n // if (index !== 0) {\n // button.setAttribute('tabindex', '-1');\n // }\n // });\n }\n\n if (autoFocusOnMount) {\n setTimeout(() => allChildrenButtonRef.current?.[0].focus());\n }\n\n // return () => {\n // allChildrenButtonRef.current?.forEach((button, index) => {\n // if (index !== 0) {\n // button.setAttribute('tabindex', '');\n // }\n // });\n // };\n }, [autoFocusOnMount]);\n\n const handleOnKeyDown = useCallback((e) => {\n if (allChildrenButtonRef.current) {\n const lastButton = allChildrenButtonRef.current[allChildrenButtonRef.current?.length - 1];\n const firstButton = allChildrenButtonRef.current[0];\n\n if (e.key === 'ArrowRight') {\n e.preventDefault();\n if (e.target !== lastButton) {\n e.target.nextSibling.focus();\n } else {\n firstButton.focus();\n }\n }\n if (e.key === 'ArrowLeft') {\n e.preventDefault();\n if (e.target !== firstButton) {\n e.target.previousSibling.focus();\n } else {\n lastButton.focus();\n }\n }\n }\n }, []);\n\n return {\n handleOnKeyDown,\n };\n};\n"],
5
+ "mappings": "AAAA;ACAA;AAYO,MAAM,wBAAwB,CAAC,EAAE,cAAc,uBAA+C;AACnG,QAAM,uBAAuB,OAA6C,IAAI;AAE9E,YAAU,MAAM;AACd,QAAI,aAAa,SAAS;AACxB,2BAAqB,UAAU,aAAa,QAAQ,iBAAiB,QAAQ;AAAA,IAM/E;AAEA,QAAI,kBAAkB;AACpB,iBAAW,MAAM,qBAAqB,UAAU,GAAG,MAAM,CAAC;AAAA,IAC5D;AAAA,EASF,GAAG,CAAC,gBAAgB,CAAC;AAErB,QAAM,kBAAkB,YAAY,CAAC,MAAM;AACzC,QAAI,qBAAqB,SAAS;AAChC,YAAM,aAAa,qBAAqB,QAAQ,qBAAqB,SAAS,SAAS;AACvF,YAAM,cAAc,qBAAqB,QAAQ;AAEjD,UAAI,EAAE,QAAQ,cAAc;AAC1B,UAAE,eAAe;AACjB,YAAI,EAAE,WAAW,YAAY;AAC3B,YAAE,OAAO,YAAY,MAAM;AAAA,QAC7B,OAAO;AACL,sBAAY,MAAM;AAAA,QACpB;AAAA,MACF;AACA,UAAI,EAAE,QAAQ,aAAa;AACzB,UAAE,eAAe;AACjB,YAAI,EAAE,WAAW,aAAa;AAC5B,YAAE,OAAO,gBAAgB,MAAM;AAAA,QACjC,OAAO;AACL,qBAAW,MAAM;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-toolbar",
3
- "version": "3.0.4-rc.4",
3
+ "version": "3.0.4-rc.5",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Toolbar",
6
6
  "files": [
@@ -86,22 +86,15 @@
86
86
  "reportFile": "tests.xml",
87
87
  "indent": 4
88
88
  },
89
- "scripts": {
90
- "dev": "cross-env NODE_ENV=development node ../../scripts/build/build.mjs --watch",
91
- "test": "node ../../scripts/testing/test.mjs",
92
- "lint": "node ../../scripts/lint.mjs",
93
- "dts": "node ../../scripts/dts.mjs",
94
- "build": "cross-env NODE_ENV=production node ../../scripts/build/build.mjs"
95
- },
96
89
  "dependencies": {
97
- "@elliemae/ds-button": "3.0.4-rc.4",
98
- "@elliemae/ds-classnames": "3.0.4-rc.4",
99
- "@elliemae/ds-grid": "3.0.4-rc.4",
100
- "@elliemae/ds-icons": "3.0.4-rc.4",
101
- "@elliemae/ds-popper": "3.0.4-rc.4",
102
- "@elliemae/ds-shared": "3.0.4-rc.4",
103
- "@elliemae/ds-system": "3.0.4-rc.4",
104
- "@elliemae/ds-utilities": "3.0.4-rc.4",
90
+ "@elliemae/ds-button": "3.0.4-rc.5",
91
+ "@elliemae/ds-classnames": "3.0.4-rc.5",
92
+ "@elliemae/ds-grid": "3.0.4-rc.5",
93
+ "@elliemae/ds-icons": "3.0.4-rc.5",
94
+ "@elliemae/ds-popper": "3.0.4-rc.5",
95
+ "@elliemae/ds-shared": "3.0.4-rc.5",
96
+ "@elliemae/ds-system": "3.0.4-rc.5",
97
+ "@elliemae/ds-utilities": "3.0.4-rc.5",
105
98
  "prop-types": "~15.8.1",
106
99
  "react-desc": "~4.1.3",
107
100
  "uid": "2.0.0"
@@ -121,5 +114,12 @@
121
114
  "publishConfig": {
122
115
  "access": "public",
123
116
  "typeSafety": false
117
+ },
118
+ "scripts": {
119
+ "dev": "cross-env NODE_ENV=development node ../../scripts/build/build.mjs --watch",
120
+ "test": "node ../../scripts/testing/test.mjs",
121
+ "lint": "node ../../scripts/lint.mjs",
122
+ "dts": "node ../../scripts/dts.mjs",
123
+ "build": "cross-env NODE_ENV=production node ../../scripts/build/build.mjs"
124
124
  }
125
- }
125
+ }