@artsy/palette 17.7.2 → 17.7.3
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/CHANGELOG.md +14 -0
- package/dist/utils/useFocusLock.js +41 -6
- package/dist/utils/useFocusLock.js.map +1 -1
- package/dist/utils/useFocusLock.story.d.ts +6 -0
- package/dist/utils/useFocusLock.story.js +44 -0
- package/dist/utils/useFocusLock.story.js.map +1 -0
- package/dist/utils/useMutationObserver.js +4 -0
- package/dist/utils/useMutationObserver.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# v17.7.3 (Wed Sep 22 2021)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- fix(hooks): improves focus lock and mutation observer hooks [#1045](https://github.com/artsy/palette/pull/1045) ([@dzucconi](https://github.com/dzucconi))
|
|
6
|
+
- fix(usefocuslock): handles clicks ([@dzucconi](https://github.com/dzucconi))
|
|
7
|
+
- fix(usemutationobserver): simply return if undefined ([@dzucconi](https://github.com/dzucconi))
|
|
8
|
+
|
|
9
|
+
#### Authors: 1
|
|
10
|
+
|
|
11
|
+
- Damon ([@dzucconi](https://github.com/dzucconi))
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
1
15
|
# v17.7.2 (Tue Sep 21 2021)
|
|
2
16
|
|
|
3
17
|
#### 🐛 Bug Fix
|
|
@@ -37,8 +37,10 @@ var useFocusLock = function useFocusLock(ref) {
|
|
|
37
37
|
var updateFocusableEls = (0, _react.useCallback)(function () {
|
|
38
38
|
if (ref.current === null) return;
|
|
39
39
|
setFocusableEls(Array.from(ref.current.querySelectorAll(FOCUSABLE_SELECTOR))); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
-
}, []);
|
|
41
|
-
|
|
40
|
+
}, []); // Set initial focusable elements on mount
|
|
41
|
+
|
|
42
|
+
(0, _react.useEffect)(updateFocusableEls, [updateFocusableEls]); // Detects when DOM changes and updates focusable elements
|
|
43
|
+
|
|
42
44
|
(0, _useMutationObserver.useMutationObserver)({
|
|
43
45
|
ref: ref,
|
|
44
46
|
onMutate: function onMutate(mutations) {
|
|
@@ -58,13 +60,15 @@ var useFocusLock = function useFocusLock(ref) {
|
|
|
58
60
|
}),
|
|
59
61
|
focusableIndex = _useCursor.index,
|
|
60
62
|
handlePrev = _useCursor.handlePrev,
|
|
61
|
-
handleNext = _useCursor.handleNext
|
|
63
|
+
handleNext = _useCursor.handleNext,
|
|
64
|
+
setCursor = _useCursor.setCursor; // Moves focus when index changes
|
|
62
65
|
|
|
63
|
-
(0, _react.useEffect)(function () {
|
|
64
|
-
if (!focusableEls.length) return; // Moves focus when index changes
|
|
65
66
|
|
|
67
|
+
(0, _react.useEffect)(function () {
|
|
68
|
+
if (!focusableEls.length) return;
|
|
66
69
|
focusableEls[focusableIndex].focus();
|
|
67
|
-
}, [focusableEls, focusableIndex]);
|
|
70
|
+
}, [focusableEls, focusableIndex]); // Handle keyboard navigation
|
|
71
|
+
|
|
68
72
|
(0, _react.useEffect)(function () {
|
|
69
73
|
var handleKeydown = function handleKeydown(event) {
|
|
70
74
|
switch (event.key) {
|
|
@@ -89,6 +93,37 @@ var useFocusLock = function useFocusLock(ref) {
|
|
|
89
93
|
document.removeEventListener("keydown", handleKeydown);
|
|
90
94
|
};
|
|
91
95
|
}, [handleNext, handlePrev]);
|
|
96
|
+
(0, _react.useEffect)(function () {
|
|
97
|
+
// Update the index when any focusable is clicked
|
|
98
|
+
var handleClick = function handleClick(event) {
|
|
99
|
+
if (event.target !== document.activeElement) return;
|
|
100
|
+
var index = focusableEls.findIndex(function (node) {
|
|
101
|
+
return node === event.target;
|
|
102
|
+
});
|
|
103
|
+
if (index === -1) return;
|
|
104
|
+
setCursor(index);
|
|
105
|
+
}; // If focus escapes the trap, pull it back in
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
var handleFocusIn = function handleFocusIn(event) {
|
|
109
|
+
var index = focusableEls.findIndex(function (node) {
|
|
110
|
+
return node === event.target;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
if (index === -1) {
|
|
114
|
+
event.stopImmediatePropagation();
|
|
115
|
+
focusableEls[focusableIndex].focus();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
document.addEventListener("click", handleClick);
|
|
121
|
+
document.addEventListener("focusin", handleFocusIn);
|
|
122
|
+
return function () {
|
|
123
|
+
document.removeEventListener("click", handleClick);
|
|
124
|
+
document.removeEventListener("focusin", handleFocusIn);
|
|
125
|
+
};
|
|
126
|
+
}, [focusableEls, focusableIndex, setCursor]);
|
|
92
127
|
};
|
|
93
128
|
|
|
94
129
|
exports.useFocusLock = useFocusLock;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/useFocusLock.ts"],"names":["FOCUSABLE_SELECTOR","join","useFocusLock","ref","focusableEls","setFocusableEls","updateFocusableEls","current","Array","from","querySelectorAll","onMutate","mutations","hasMeaningfullyMutated","some","mutation","addedNodes","length","removedNodes","max","focusableIndex","index","handlePrev","handleNext","focus","handleKeydown","event","key","preventDefault","stopPropagation","shiftKey","focusedElPriorToOpen","document","activeElement","addEventListener","removeEventListener"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;;;;;AAEA,IAAMA,kBAAkB,GAAG,CACzB,SADyB,EAEzB,YAFyB,EAGzB,uBAHyB,EAIzB,wBAJyB,EAKzB,0BALyB,EAMzB,wBANyB,EAOzB,gBAPyB,EAQzBC,IARyB,CAQpB,IARoB,CAA3B;AAUA;AACA;AACA;;AACO,IAAMC,YAAY,GAAG,SAAfA,YAAe,CAC1BC,GAD0B,EAEvB;AAAA,kBACqC,qBAAwB,EAAxB,CADrC;AAAA;AAAA,MACIC,YADJ;AAAA,MACkBC,eADlB;;AAGH,MAAMC,kBAAkB,GAAG,wBAAY,YAAM;AAC3C,QAAIH,GAAG,CAACI,OAAJ,KAAgB,IAApB,EAA0B;AAE1BF,IAAAA,eAAe,CACbG,KAAK,CAACC,IAAN,CAAWN,GAAG,CAACI,OAAJ,CAAYG,gBAAZ,CAA0CV,kBAA1C,CAAX,CADa,CAAf,CAH2C,CAM3C;AACD,GAP0B,EAOxB,EAPwB,CAA3B
|
|
1
|
+
{"version":3,"sources":["../../src/utils/useFocusLock.ts"],"names":["FOCUSABLE_SELECTOR","join","useFocusLock","ref","focusableEls","setFocusableEls","updateFocusableEls","current","Array","from","querySelectorAll","onMutate","mutations","hasMeaningfullyMutated","some","mutation","addedNodes","length","removedNodes","max","focusableIndex","index","handlePrev","handleNext","setCursor","focus","handleKeydown","event","key","preventDefault","stopPropagation","shiftKey","focusedElPriorToOpen","document","activeElement","addEventListener","removeEventListener","handleClick","target","findIndex","node","handleFocusIn","stopImmediatePropagation"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;;;;;AAEA,IAAMA,kBAAkB,GAAG,CACzB,SADyB,EAEzB,YAFyB,EAGzB,uBAHyB,EAIzB,wBAJyB,EAKzB,0BALyB,EAMzB,wBANyB,EAOzB,gBAPyB,EAQzBC,IARyB,CAQpB,IARoB,CAA3B;AAUA;AACA;AACA;;AACO,IAAMC,YAAY,GAAG,SAAfA,YAAe,CAC1BC,GAD0B,EAEvB;AAAA,kBACqC,qBAAwB,EAAxB,CADrC;AAAA;AAAA,MACIC,YADJ;AAAA,MACkBC,eADlB;;AAGH,MAAMC,kBAAkB,GAAG,wBAAY,YAAM;AAC3C,QAAIH,GAAG,CAACI,OAAJ,KAAgB,IAApB,EAA0B;AAE1BF,IAAAA,eAAe,CACbG,KAAK,CAACC,IAAN,CAAWN,GAAG,CAACI,OAAJ,CAAYG,gBAAZ,CAA0CV,kBAA1C,CAAX,CADa,CAAf,CAH2C,CAM3C;AACD,GAP0B,EAOxB,EAPwB,CAA3B,CAHG,CAYH;;AACA,wBAAUM,kBAAV,EAA8B,CA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CK,aAAxC;AACD,KAHD;AAID,GA7BD,EA6BG,CAACrC,YAAD,EAAegB,cAAf,EAA+BI,SAA/B,CA7BH;AA8BD,CA5GM","sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\"\nimport { useCursor } from \"use-cursor\"\nimport { useMutationObserver } from \"./useMutationObserver\"\n\nconst FOCUSABLE_SELECTOR = [\n \"a[href]\",\n \"area[href]\",\n \"input:not([disabled])\",\n \"select:not([disabled])\",\n \"textarea:not([disabled])\",\n \"button:not([disabled])\",\n '[tabindex=\"0\"]',\n].join(\", \")\n\n/**\n * Locks focus within the given element\n */\nexport const useFocusLock = (\n ref: React.MutableRefObject<HTMLElement | null>\n) => {\n const [focusableEls, setFocusableEls] = useState<HTMLElement[]>([])\n\n const updateFocusableEls = useCallback(() => {\n if (ref.current === null) return\n\n setFocusableEls(\n Array.from(ref.current.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR))\n )\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n // Set initial focusable elements on mount\n useEffect(updateFocusableEls, [updateFocusableEls])\n\n // Detects when DOM changes and updates focusable elements\n useMutationObserver({\n ref,\n onMutate: (mutations) => {\n // Check to see if any of the mutations has either added or removed nodes\n const hasMeaningfullyMutated = mutations.some((mutation) => {\n return (\n mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0\n )\n })\n\n if (hasMeaningfullyMutated) {\n updateFocusableEls()\n }\n },\n })\n\n const {\n index: focusableIndex,\n handlePrev,\n handleNext,\n setCursor,\n } = useCursor({\n max: focusableEls.length,\n })\n\n // Moves focus when index changes\n useEffect(() => {\n if (!focusableEls.length) return\n focusableEls[focusableIndex].focus()\n }, [focusableEls, focusableIndex])\n\n // Handle keyboard navigation\n useEffect(() => {\n const handleKeydown = (event: KeyboardEvent) => {\n switch (event.key) {\n case \"Tab\":\n // Lock focus within element\n event.preventDefault()\n event.stopPropagation()\n\n // Move focus up or down\n event.shiftKey ? handlePrev() : handleNext()\n break\n default:\n break\n }\n }\n\n const focusedElPriorToOpen = document.activeElement as HTMLElement\n\n document.addEventListener(\"keydown\", handleKeydown)\n\n return () => {\n // Return the focus\n focusedElPriorToOpen.focus()\n\n document.removeEventListener(\"keydown\", handleKeydown)\n }\n }, [handleNext, handlePrev])\n\n useEffect(() => {\n // Update the index when any focusable is clicked\n const handleClick = (event: MouseEvent) => {\n if (event.target !== document.activeElement) return\n\n const index = focusableEls.findIndex((node) => node === event.target)\n\n if (index === -1) return\n\n setCursor(index)\n }\n\n // If focus escapes the trap, pull it back in\n const handleFocusIn = (event: FocusEvent) => {\n const index = focusableEls.findIndex((node) => node === event.target)\n\n if (index === -1) {\n event.stopImmediatePropagation()\n focusableEls[focusableIndex].focus()\n return\n }\n }\n\n document.addEventListener(\"click\", handleClick)\n document.addEventListener(\"focusin\", handleFocusIn)\n return () => {\n document.removeEventListener(\"click\", handleClick)\n document.removeEventListener(\"focusin\", handleFocusIn)\n }\n }, [focusableEls, focusableIndex, setCursor])\n}\n"],"file":"useFocusLock.js"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Default = exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
|
|
12
|
+
var _useFocusLock = require("./useFocusLock");
|
|
13
|
+
|
|
14
|
+
var _Input = require("../elements/Input");
|
|
15
|
+
|
|
16
|
+
var _Button = require("../elements/Button");
|
|
17
|
+
|
|
18
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
19
|
+
|
|
20
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
|
|
22
|
+
var _default = {
|
|
23
|
+
title: "Hooks/useFocusLock"
|
|
24
|
+
};
|
|
25
|
+
exports.default = _default;
|
|
26
|
+
|
|
27
|
+
var Default = function Default() {
|
|
28
|
+
var ref = (0, _react.useRef)(null);
|
|
29
|
+
(0, _useFocusLock.useFocusLock)(ref);
|
|
30
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
31
|
+
placeholder: "Not focusable"
|
|
32
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
33
|
+
ref: ref
|
|
34
|
+
}, /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
35
|
+
placeholder: "Focusable"
|
|
36
|
+
}), /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
37
|
+
placeholder: "Focusable"
|
|
38
|
+
}), /*#__PURE__*/_react.default.createElement(_Button.Button, null, "Focusable")), /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
39
|
+
placeholder: "Not focusable"
|
|
40
|
+
}));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
exports.Default = Default;
|
|
44
|
+
//# sourceMappingURL=useFocusLock.story.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/useFocusLock.story.tsx"],"names":["title","Default","ref"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;eAEe;AACbA,EAAAA,KAAK,EAAE;AADM,C;;;AAIR,IAAMC,OAAO,GAAG,SAAVA,OAAU,GAAM;AAC3B,MAAMC,GAAG,GAAG,mBAA8B,IAA9B,CAAZ;AAEA,kCAAaA,GAAb;AAEA,sBACE,yEACE,6BAAC,YAAD;AAAO,IAAA,WAAW,EAAC;AAAnB,IADF,eAEE;AAAK,IAAA,GAAG,EAAEA;AAAV,kBACE,6BAAC,YAAD;AAAO,IAAA,WAAW,EAAC;AAAnB,IADF,eAEE,6BAAC,YAAD;AAAO,IAAA,WAAW,EAAC;AAAnB,IAFF,eAGE,6BAAC,cAAD,oBAHF,CAFF,eAOE,6BAAC,YAAD;AAAO,IAAA,WAAW,EAAC;AAAnB,IAPF,CADF;AAWD,CAhBM","sourcesContent":["import React, { useRef } from \"react\"\nimport { useFocusLock } from \"./useFocusLock\"\nimport { Input } from \"../elements/Input\"\nimport { Button } from \"../elements/Button\"\n\nexport default {\n title: \"Hooks/useFocusLock\",\n}\n\nexport const Default = () => {\n const ref = useRef<HTMLDivElement | null>(null)\n\n useFocusLock(ref)\n\n return (\n <>\n <Input placeholder=\"Not focusable\" />\n <div ref={ref}>\n <Input placeholder=\"Focusable\" />\n <Input placeholder=\"Focusable\" />\n <Button>Focusable</Button>\n </div>\n <Input placeholder=\"Not focusable\" />\n </>\n )\n}\n"],"file":"useFocusLock.story.js"}
|
|
@@ -21,6 +21,10 @@ var useMutationObserver = function useMutationObserver(_ref) {
|
|
|
21
21
|
} : _ref$options,
|
|
22
22
|
ref = _ref.ref;
|
|
23
23
|
(0, _react.useEffect)(function () {
|
|
24
|
+
if (typeof MutationObserver === "undefined") {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
if (ref.current) {
|
|
25
29
|
var observer = new MutationObserver(onMutate); // Start observing the target node for configured mutations
|
|
26
30
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/useMutationObserver.ts"],"names":["useMutationObserver","onMutate","options","attributes","characterData","childList","subtree","ref","
|
|
1
|
+
{"version":3,"sources":["../../src/utils/useMutationObserver.ts"],"names":["useMutationObserver","onMutate","options","attributes","characterData","childList","subtree","ref","MutationObserver","current","observer","observe","disconnect"],"mappings":";;;;;;;AACA;;AAQA;AACA;AACA;AACO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAsB,OASR;AAAA,MARzBC,QAQyB,QARzBA,QAQyB;AAAA,0BAPzBC,OAOyB;AAAA,MAPzBA,OAOyB,6BAPf;AACRC,IAAAA,UAAU,EAAE,IADJ;AAERC,IAAAA,aAAa,EAAE,IAFP;AAGRC,IAAAA,SAAS,EAAE,IAHH;AAIRC,IAAAA,OAAO,EAAE;AAJD,GAOe;AAAA,MADzBC,GACyB,QADzBA,GACyB;AACzB,wBAAU,YAAM;AACd,QAAI,OAAOC,gBAAP,KAA4B,WAAhC,EAA6C;AAC3C;AACD;;AAED,QAAID,GAAG,CAACE,OAAR,EAAiB;AACf,UAAMC,QAAQ,GAAG,IAAIF,gBAAJ,CAAqBP,QAArB,CAAjB,CADe,CAGf;;AACAS,MAAAA,QAAQ,CAACC,OAAT,CAAiBJ,GAAG,CAACE,OAArB,EAA8BP,OAA9B;AAEA,aAAO,YAAM;AACXQ,QAAAA,QAAQ,CAACE,UAAT;AACD,OAFD;AAGD,KAda,CAed;;AACD,GAhBD,EAgBG,CAACX,QAAD,EAAWC,OAAX,CAhBH;AAiBD,CA3BM","sourcesContent":["import type { MutableRefObject } from \"react\"\nimport { useEffect } from \"react\"\n\ninterface UseMutationObserver {\n onMutate: MutationCallback\n options?: MutationObserverInit\n ref: MutableRefObject<HTMLElement | null>\n}\n\n/**\n * Accepts a ref and calls the `onMutate` callback when mutations are observed.\n */\nexport const useMutationObserver = ({\n onMutate,\n options = {\n attributes: true,\n characterData: true,\n childList: true,\n subtree: true,\n },\n ref,\n}: UseMutationObserver) => {\n useEffect(() => {\n if (typeof MutationObserver === \"undefined\") {\n return\n }\n\n if (ref.current) {\n const observer = new MutationObserver(onMutate)\n\n // Start observing the target node for configured mutations\n observer.observe(ref.current, options)\n\n return () => {\n observer.disconnect()\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [onMutate, options])\n}\n"],"file":"useMutationObserver.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artsy/palette",
|
|
3
|
-
"version": "17.7.
|
|
3
|
+
"version": "17.7.3",
|
|
4
4
|
"description": "Design system library for react components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -175,5 +175,5 @@
|
|
|
175
175
|
"<rootDir>/www/"
|
|
176
176
|
]
|
|
177
177
|
},
|
|
178
|
-
"gitHead": "
|
|
178
|
+
"gitHead": "c5b11add7b8b28ae210473956532c84d318bd947"
|
|
179
179
|
}
|