@primer/react 0.0.0-20260311021722 → 0.0.0-20260311072240
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 +2 -2
- package/dist/TextInput/TextInput.d.ts.map +1 -1
- package/dist/TextInput/TextInput.js +31 -5
- package/dist/TreeView/useRovingTabIndex.d.ts +0 -14
- package/dist/TreeView/useRovingTabIndex.d.ts.map +1 -1
- package/dist/TreeView/useRovingTabIndex.js +16 -94
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20260311072240
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- Fake entry to force publishing
|
|
8
8
|
|
|
9
|
-
- [#
|
|
9
|
+
- [#7600](https://github.com/primer/react/pull/7600) [`77be5b9`](https://github.com/primer/react/commit/77be5b98b788d49d8cc695b96e8cb412d7ca2935) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(TextInput): skip redundant character counter updates
|
|
10
10
|
|
|
11
11
|
## 38.15.0
|
|
12
12
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../src/TextInput/TextInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAwD,MAAM,OAAO,CAAA;AAE5E,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAO/F,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,yCAAyC,CAAA;AAQ/E,MAAM,MAAM,4BAA4B,GAAG;IACzC,uEAAuE;IACvE,IAAI,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACxB,2DAA2D;IAC3D,OAAO,CAAC,EA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;;;;;QAKI;IACJ,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAAA;IAChD,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,SAAS,CAAA;IACnD;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,SAAS,CAAA;IACpD;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAA;IACvE;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,GAAG,OAAO,CACT,IAAI,CACF,kBAAkB,EAChB,OAAO,GACP,UAAU,GACV,UAAU,GACV,WAAW,GACX,OAAO,GACP,UAAU,GACV,UAAU,GACV,SAAS,GACT,MAAM,GACN,kBAAkB,CACrB,CACF,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC,wBAAwB,CAAC,OAAO,CAAC,EAAE,4BAA4B,CAAC,CAAA;;;;;;;;;;;AA+PzG,wBAGE"}
|
|
@@ -51,6 +51,10 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
|
51
51
|
const [isOverLimit, setIsOverLimit] = useState(false);
|
|
52
52
|
const [screenReaderMessage, setScreenReaderMessage] = useState('');
|
|
53
53
|
const characterCounterRef = useRef(null);
|
|
54
|
+
const lastCountedLengthRef = useRef(null);
|
|
55
|
+
const lastCharacterCountRef = useRef('');
|
|
56
|
+
const lastIsOverLimitRef = useRef(false);
|
|
57
|
+
const lastScreenReaderMessageRef = useRef('');
|
|
54
58
|
|
|
55
59
|
// this class is necessary to style FilterSearch, plz no touchy!
|
|
56
60
|
const wrapperClasses = clsx(className, 'TextInput-wrapper');
|
|
@@ -84,17 +88,31 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
|
84
88
|
if (characterLimit) {
|
|
85
89
|
characterCounterRef.current = new CharacterCounter({
|
|
86
90
|
onCountUpdate: (count, overLimit, message) => {
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
if (message !== lastCharacterCountRef.current) {
|
|
92
|
+
lastCharacterCountRef.current = message;
|
|
93
|
+
setCharacterCount(message);
|
|
94
|
+
}
|
|
95
|
+
if (overLimit !== lastIsOverLimitRef.current) {
|
|
96
|
+
lastIsOverLimitRef.current = overLimit;
|
|
97
|
+
setIsOverLimit(overLimit);
|
|
98
|
+
}
|
|
89
99
|
},
|
|
90
100
|
onScreenReaderAnnounce: message_0 => {
|
|
91
|
-
|
|
101
|
+
if (message_0 !== lastScreenReaderMessageRef.current) {
|
|
102
|
+
lastScreenReaderMessageRef.current = message_0;
|
|
103
|
+
setScreenReaderMessage(message_0);
|
|
104
|
+
}
|
|
92
105
|
}
|
|
93
106
|
});
|
|
107
|
+
lastCountedLengthRef.current = null;
|
|
94
108
|
return () => {
|
|
95
109
|
var _characterCounterRef$;
|
|
96
110
|
(_characterCounterRef$ = characterCounterRef.current) === null || _characterCounterRef$ === void 0 ? void 0 : _characterCounterRef$.cleanup();
|
|
97
111
|
characterCounterRef.current = null;
|
|
112
|
+
lastCountedLengthRef.current = null;
|
|
113
|
+
lastCharacterCountRef.current = '';
|
|
114
|
+
lastIsOverLimitRef.current = false;
|
|
115
|
+
lastScreenReaderMessageRef.current = '';
|
|
98
116
|
};
|
|
99
117
|
}
|
|
100
118
|
}, [characterLimit]);
|
|
@@ -103,14 +121,22 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
|
103
121
|
useEffect(() => {
|
|
104
122
|
if (characterLimit && characterCounterRef.current) {
|
|
105
123
|
const currentValue = value !== undefined ? String(value) : defaultValue !== undefined ? String(defaultValue) : '';
|
|
106
|
-
|
|
124
|
+
const currentLength = currentValue.length;
|
|
125
|
+
if (currentLength !== lastCountedLengthRef.current) {
|
|
126
|
+
lastCountedLengthRef.current = currentLength;
|
|
127
|
+
characterCounterRef.current.updateCharacterCount(currentLength, characterLimit);
|
|
128
|
+
}
|
|
107
129
|
}
|
|
108
130
|
}, [value, defaultValue, characterLimit]);
|
|
109
131
|
|
|
110
132
|
// Handle input change with character counter
|
|
111
133
|
const handleInputChange = useCallback(e_2 => {
|
|
112
134
|
if (characterLimit && characterCounterRef.current) {
|
|
113
|
-
|
|
135
|
+
const currentLength_0 = e_2.target.value.length;
|
|
136
|
+
if (currentLength_0 !== lastCountedLengthRef.current) {
|
|
137
|
+
lastCountedLengthRef.current = currentLength_0;
|
|
138
|
+
characterCounterRef.current.updateCharacterCount(currentLength_0, characterLimit);
|
|
139
|
+
}
|
|
114
140
|
}
|
|
115
141
|
onChange === null || onChange === void 0 ? void 0 : onChange(e_2);
|
|
116
142
|
}, [onChange, characterLimit]);
|
|
@@ -5,20 +5,6 @@ export declare function useRovingTabIndex({ containerRef, mouseDownRef, }: {
|
|
|
5
5
|
}): void;
|
|
6
6
|
export declare function getNextFocusableElement(activeElement: HTMLElement, event: KeyboardEvent): HTMLElement | undefined;
|
|
7
7
|
export declare function getElementState(element: HTMLElement): 'open' | 'closed' | 'end';
|
|
8
|
-
/**
|
|
9
|
-
* Find the next or previous visible treeitem using direct DOM traversal.
|
|
10
|
-
*
|
|
11
|
-
* PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
|
|
12
|
-
* siblings and parent/child edges directly, rather than creating a TreeWalker
|
|
13
|
-
* that scans from the root to find the current element on every keystroke.
|
|
14
|
-
*
|
|
15
|
-
* NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
|
|
16
|
-
* (returning null when !isExpanded). Because collapsed subtree children are
|
|
17
|
-
* never in the DOM, we can safely skip them by only entering children of nodes
|
|
18
|
-
* with aria-expanded="true". If SubTree ever changes to keep collapsed children
|
|
19
|
-
* mounted (e.g. via CSS display:none), this logic would need to add filtering
|
|
20
|
-
* for items inside collapsed parents.
|
|
21
|
-
*/
|
|
22
8
|
export declare function getVisibleElement(element: HTMLElement, direction: 'next' | 'previous'): HTMLElement | undefined;
|
|
23
9
|
export declare function getFirstChildElement(element: HTMLElement): HTMLElement | undefined;
|
|
24
10
|
export declare function getParentElement(element: HTMLElement): HTMLElement | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRovingTabIndex.d.ts","sourceRoot":"","sources":["../../src/TreeView/useRovingTabIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,YAAY,GACb,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAC1C,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;CACvC,QAwDA;AAID,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,CAyDjH;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAa/E;AAED
|
|
1
|
+
{"version":3,"file":"useRovingTabIndex.d.ts","sourceRoot":"","sources":["../../src/TreeView/useRovingTabIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,YAAY,GACb,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAC1C,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;CACvC,QAwDA;AAID,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,CAyDjH;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAa/E;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAwB/G;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAGlF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI9E;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI7E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAuB5E"}
|
|
@@ -123,103 +123,25 @@ function getElementState(element) {
|
|
|
123
123
|
return 'end';
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Find the next or previous visible treeitem using direct DOM traversal.
|
|
129
|
-
*
|
|
130
|
-
* PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
|
|
131
|
-
* siblings and parent/child edges directly, rather than creating a TreeWalker
|
|
132
|
-
* that scans from the root to find the current element on every keystroke.
|
|
133
|
-
*
|
|
134
|
-
* NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
|
|
135
|
-
* (returning null when !isExpanded). Because collapsed subtree children are
|
|
136
|
-
* never in the DOM, we can safely skip them by only entering children of nodes
|
|
137
|
-
* with aria-expanded="true". If SubTree ever changes to keep collapsed children
|
|
138
|
-
* mounted (e.g. via CSS display:none), this logic would need to add filtering
|
|
139
|
-
* for items inside collapsed parents.
|
|
140
|
-
*/
|
|
141
126
|
function getVisibleElement(element, direction) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// Otherwise, walk up the tree looking for a next sibling
|
|
155
|
-
let current = element;
|
|
156
|
-
while (current) {
|
|
157
|
-
const next = getNextSiblingTreeItem(current);
|
|
158
|
-
if (next) return next;
|
|
159
|
-
|
|
160
|
-
// No next sibling at this level, try the parent's next sibling
|
|
161
|
-
current = getParentElement(current);
|
|
162
|
-
}
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
function getPreviousVisibleElement(element) {
|
|
166
|
-
const prev = getPreviousSiblingTreeItem(element);
|
|
167
|
-
if (prev) {
|
|
168
|
-
// Navigate to the deepest last visible descendant of the previous sibling
|
|
169
|
-
return getDeepestLastDescendant(prev);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// No previous sibling, the parent is the previous visible element
|
|
173
|
-
return getParentElement(element);
|
|
174
|
-
}
|
|
127
|
+
const root = element.closest('[role=tree]');
|
|
128
|
+
if (!root) return;
|
|
129
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, node => {
|
|
130
|
+
if (!(node instanceof HTMLElement)) return NodeFilter.FILTER_SKIP;
|
|
131
|
+
return node.getAttribute('role') === 'treeitem' ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
132
|
+
});
|
|
133
|
+
let current = walker.firstChild();
|
|
134
|
+
while (current !== element) {
|
|
135
|
+
current = walker.nextNode();
|
|
136
|
+
}
|
|
137
|
+
let next = direction === 'next' ? walker.nextNode() : walker.previousNode();
|
|
175
138
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
*/
|
|
181
|
-
function getDeepestLastDescendant(element) {
|
|
182
|
-
let current = element;
|
|
183
|
-
while (current.getAttribute('aria-expanded') === 'true') {
|
|
184
|
-
const lastChild = getLastChildTreeItem(current);
|
|
185
|
-
if (!lastChild) break;
|
|
186
|
-
current = lastChild;
|
|
187
|
-
}
|
|
188
|
-
return current;
|
|
189
|
-
}
|
|
190
|
-
function getNextSiblingTreeItem(element) {
|
|
191
|
-
let sibling = element.nextElementSibling;
|
|
192
|
-
while (sibling) {
|
|
193
|
-
if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
|
|
194
|
-
return sibling;
|
|
195
|
-
}
|
|
196
|
-
sibling = sibling.nextElementSibling;
|
|
197
|
-
}
|
|
198
|
-
return undefined;
|
|
199
|
-
}
|
|
200
|
-
function getPreviousSiblingTreeItem(element) {
|
|
201
|
-
let sibling = element.previousElementSibling;
|
|
202
|
-
while (sibling) {
|
|
203
|
-
if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
|
|
204
|
-
return sibling;
|
|
205
|
-
}
|
|
206
|
-
sibling = sibling.previousElementSibling;
|
|
207
|
-
}
|
|
208
|
-
return undefined;
|
|
209
|
-
}
|
|
210
|
-
function getLastChildTreeItem(element) {
|
|
211
|
-
// Find the [role=group] child (the subtree container), then get its last treeitem
|
|
212
|
-
for (let i = element.children.length - 1; i >= 0; i--) {
|
|
213
|
-
const child = element.children[i];
|
|
214
|
-
if (child instanceof HTMLElement && child.getAttribute('role') === 'group') {
|
|
215
|
-
let lastChild = child.lastElementChild;
|
|
216
|
-
while (lastChild && !(lastChild instanceof HTMLElement && lastChild.getAttribute('role') === 'treeitem')) {
|
|
217
|
-
lastChild = lastChild.previousElementSibling;
|
|
218
|
-
}
|
|
219
|
-
return lastChild instanceof HTMLElement ? lastChild : undefined;
|
|
220
|
-
}
|
|
139
|
+
// If next element is nested inside a collapsed subtree, continue iterating
|
|
140
|
+
while (next instanceof HTMLElement && (_next$parentElement = next.parentElement) !== null && _next$parentElement !== void 0 && _next$parentElement.closest('[role=treeitem][aria-expanded=false]')) {
|
|
141
|
+
var _next$parentElement;
|
|
142
|
+
next = direction === 'next' ? walker.nextNode() : walker.previousNode();
|
|
221
143
|
}
|
|
222
|
-
return undefined;
|
|
144
|
+
return next instanceof HTMLElement ? next : undefined;
|
|
223
145
|
}
|
|
224
146
|
function getFirstChildElement(element) {
|
|
225
147
|
const firstChild = element.querySelector('[role=treeitem]');
|
package/package.json
CHANGED