@primer/components 0.0.0-2021927182835 → 0.0.0-2021927184113
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 +4 -2
- package/dist/browser.esm.js +1 -1
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +27 -27
- package/dist/browser.umd.js.map +1 -1
- package/lib/TextInputWithTokens.js +25 -12
- package/lib-esm/TextInputWithTokens.js +25 -13
- package/package.json +1 -1
@@ -25,6 +25,8 @@ var _TextInputWrapper = _interopRequireDefault(require("./_TextInputWrapper"));
|
|
25
25
|
|
26
26
|
var _Box = _interopRequireDefault(require("./Box"));
|
27
27
|
|
28
|
+
var _iterateFocusableElements = require("./utils/iterateFocusableElements");
|
29
|
+
|
28
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
29
31
|
|
30
32
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
@@ -98,14 +100,25 @@ function TextInputWithTokensInnerComponent({
|
|
98
100
|
}, [selectedTokenIndex]);
|
99
101
|
|
100
102
|
const handleTokenRemove = tokenId => {
|
101
|
-
onTokenRemove(tokenId);
|
103
|
+
onTokenRemove(tokenId); // HACK: wait a tick for the the token node to be removed from the DOM
|
102
104
|
|
103
|
-
|
104
|
-
var _containerRef$current2;
|
105
|
+
setTimeout(() => {
|
106
|
+
var _containerRef$current2, _containerRef$current3;
|
105
107
|
|
106
|
-
const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex];
|
107
|
-
|
108
|
-
|
108
|
+
const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex || 0]; // when removing the first token by keying "Backspace" or "Delete",
|
109
|
+
// `nextFocusableElement` is the div that wraps the input
|
110
|
+
|
111
|
+
const firstFocusable = nextElementToFocus && (0, _iterateFocusableElements.isFocusable)(nextElementToFocus) ? nextElementToFocus : Array.from(((_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.children) || []).find(el => (0, _iterateFocusableElements.isFocusable)(el));
|
112
|
+
|
113
|
+
if (firstFocusable) {
|
114
|
+
firstFocusable.focus();
|
115
|
+
} else {
|
116
|
+
var _ref$current;
|
117
|
+
|
118
|
+
// if there are no tokens left, focus the input
|
119
|
+
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
120
|
+
}
|
121
|
+
}, 0);
|
109
122
|
};
|
110
123
|
|
111
124
|
const handleTokenFocus = tokenIndex => () => {
|
@@ -118,9 +131,9 @@ function TextInputWithTokensInnerComponent({
|
|
118
131
|
|
119
132
|
const handleTokenKeyUp = e => {
|
120
133
|
if (e.key === 'Escape') {
|
121
|
-
var _ref$
|
134
|
+
var _ref$current2;
|
122
135
|
|
123
|
-
(_ref$
|
136
|
+
(_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focus();
|
124
137
|
}
|
125
138
|
};
|
126
139
|
|
@@ -130,13 +143,13 @@ function TextInputWithTokensInnerComponent({
|
|
130
143
|
};
|
131
144
|
|
132
145
|
const handleInputKeyDown = e => {
|
133
|
-
var _ref$
|
146
|
+
var _ref$current3;
|
134
147
|
|
135
148
|
if (onKeyDown) {
|
136
149
|
onKeyDown(e);
|
137
150
|
}
|
138
151
|
|
139
|
-
if ((_ref$
|
152
|
+
if ((_ref$current3 = ref.current) !== null && _ref$current3 !== void 0 && _ref$current3.value) {
|
140
153
|
return;
|
141
154
|
}
|
142
155
|
|
@@ -157,9 +170,9 @@ function TextInputWithTokensInnerComponent({
|
|
157
170
|
|
158
171
|
|
159
172
|
setTimeout(() => {
|
160
|
-
var _ref$
|
173
|
+
var _ref$current4;
|
161
174
|
|
162
|
-
(_ref$
|
175
|
+
(_ref$current4 = ref.current) === null || _ref$current4 === void 0 ? void 0 : _ref$current4.select();
|
163
176
|
}, 0);
|
164
177
|
}
|
165
178
|
};
|
@@ -9,7 +9,8 @@ import Token from './Token/Token';
|
|
9
9
|
import { useProvidedRefOrCreate } from './hooks';
|
10
10
|
import UnstyledTextInput from './_UnstyledTextInput';
|
11
11
|
import TextInputWrapper from './_TextInputWrapper';
|
12
|
-
import Box from './Box';
|
12
|
+
import Box from './Box';
|
13
|
+
import { isFocusable } from './utils/iterateFocusableElements'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
13
14
|
|
14
15
|
// using forwardRef is important so that other components (ex. Autocomplete) can use the ref
|
15
16
|
function TextInputWithTokensInnerComponent({
|
@@ -76,14 +77,25 @@ function TextInputWithTokensInnerComponent({
|
|
76
77
|
}, [selectedTokenIndex]);
|
77
78
|
|
78
79
|
const handleTokenRemove = tokenId => {
|
79
|
-
onTokenRemove(tokenId);
|
80
|
+
onTokenRemove(tokenId); // HACK: wait a tick for the the token node to be removed from the DOM
|
80
81
|
|
81
|
-
|
82
|
-
var _containerRef$current2;
|
82
|
+
setTimeout(() => {
|
83
|
+
var _containerRef$current2, _containerRef$current3;
|
83
84
|
|
84
|
-
const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex];
|
85
|
-
|
86
|
-
|
85
|
+
const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex || 0]; // when removing the first token by keying "Backspace" or "Delete",
|
86
|
+
// `nextFocusableElement` is the div that wraps the input
|
87
|
+
|
88
|
+
const firstFocusable = nextElementToFocus && isFocusable(nextElementToFocus) ? nextElementToFocus : Array.from(((_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.children) || []).find(el => isFocusable(el));
|
89
|
+
|
90
|
+
if (firstFocusable) {
|
91
|
+
firstFocusable.focus();
|
92
|
+
} else {
|
93
|
+
var _ref$current;
|
94
|
+
|
95
|
+
// if there are no tokens left, focus the input
|
96
|
+
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
97
|
+
}
|
98
|
+
}, 0);
|
87
99
|
};
|
88
100
|
|
89
101
|
const handleTokenFocus = tokenIndex => () => {
|
@@ -96,9 +108,9 @@ function TextInputWithTokensInnerComponent({
|
|
96
108
|
|
97
109
|
const handleTokenKeyUp = e => {
|
98
110
|
if (e.key === 'Escape') {
|
99
|
-
var _ref$
|
111
|
+
var _ref$current2;
|
100
112
|
|
101
|
-
(_ref$
|
113
|
+
(_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focus();
|
102
114
|
}
|
103
115
|
};
|
104
116
|
|
@@ -108,13 +120,13 @@ function TextInputWithTokensInnerComponent({
|
|
108
120
|
};
|
109
121
|
|
110
122
|
const handleInputKeyDown = e => {
|
111
|
-
var _ref$
|
123
|
+
var _ref$current3;
|
112
124
|
|
113
125
|
if (onKeyDown) {
|
114
126
|
onKeyDown(e);
|
115
127
|
}
|
116
128
|
|
117
|
-
if ((_ref$
|
129
|
+
if ((_ref$current3 = ref.current) !== null && _ref$current3 !== void 0 && _ref$current3.value) {
|
118
130
|
return;
|
119
131
|
}
|
120
132
|
|
@@ -135,9 +147,9 @@ function TextInputWithTokensInnerComponent({
|
|
135
147
|
|
136
148
|
|
137
149
|
setTimeout(() => {
|
138
|
-
var _ref$
|
150
|
+
var _ref$current4;
|
139
151
|
|
140
|
-
(_ref$
|
152
|
+
(_ref$current4 = ref.current) === null || _ref$current4 === void 0 ? void 0 : _ref$current4.select();
|
141
153
|
}, 0);
|
142
154
|
}
|
143
155
|
};
|