@primer/react 0.0.0-20260623170141 → 0.0.0-20260623184653
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 +10 -16
- package/dist/ConfirmationDialog/useConfirm.d.ts.map +1 -1
- package/dist/ConfirmationDialog/useConfirm.js +4 -8
- package/dist/Radio/Radio.d.ts.map +1 -1
- package/dist/Radio/Radio.js +1 -2
- package/dist/RadioGroup/RadioGroup.js +0 -1
- package/dist/RelativeTime/RelativeTime.js +0 -1
- package/dist/ScrollableRegion/ScrollableRegion.d.ts.map +1 -1
- package/dist/ScrollableRegion/ScrollableRegion.js +0 -1
- package/dist/SegmentedControl/SegmentedControl.d.ts.map +1 -1
- package/dist/SegmentedControl/SegmentedControl.js +0 -1
- package/dist/SegmentedControl/SegmentedControlButton.d.ts.map +1 -1
- package/dist/SegmentedControl/SegmentedControlButton.js +0 -1
- package/dist/SegmentedControl/SegmentedControlIconButton.d.ts.map +1 -1
- package/dist/SegmentedControl/SegmentedControlIconButton.js +0 -1
- package/dist/Select/Select.d.ts.map +1 -1
- package/dist/Select/Select.js +2 -6
- package/dist/SideNav.d.ts.map +1 -1
- package/dist/SideNav.js +0 -2
- package/dist/Skeleton/SkeletonBox.d.ts +0 -1
- package/dist/Skeleton/SkeletonBox.d.ts.map +1 -1
- package/dist/Skeleton/SkeletonBox.js +47 -54
- package/dist/SkeletonText/SkeletonText.d.ts.map +1 -1
- package/dist/SkeletonText/SkeletonText.js +2 -2
- package/dist/Spinner/Spinner.js +0 -1
- package/dist/TextInput/TextInput.d.ts.map +1 -1
- package/dist/TextInput/TextInput.js +27 -68
- package/dist/Textarea/Textarea.d.ts.map +1 -1
- package/dist/Textarea/Textarea.js +158 -186
- package/dist/UnderlineNav/UnderlineNav.d.ts.map +1 -1
- package/dist/UnderlineNav/UnderlineNav.js +52 -12
- package/dist/_VisuallyHidden.js +2 -2
- package/dist/_VisuallyHidden.module.css.js +2 -2
- package/dist/live-region/Announce.d.ts.map +1 -1
- package/dist/live-region/Announce.js +51 -36
- package/dist/utils/character-counter.d.ts +16 -21
- package/dist/utils/character-counter.d.ts.map +1 -1
- package/dist/utils/character-counter.js +23 -59
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c } from 'react-compiler-runtime';
|
|
2
2
|
import { announceFromElement } from '@primer/live-region-element';
|
|
3
|
-
import { useRef,
|
|
3
|
+
import { useRef, useEffect } from 'react';
|
|
4
4
|
import { useEffectOnce } from '../internal/hooks/useEffectOnce.js';
|
|
5
5
|
import { useEffectCallback } from '../internal/hooks/useEffectCallback.js';
|
|
6
6
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -11,7 +11,7 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
11
11
|
* will also announce any changes to the text content of `children`
|
|
12
12
|
*/
|
|
13
13
|
function Announce(props) {
|
|
14
|
-
const $ = c(
|
|
14
|
+
const $ = c(24);
|
|
15
15
|
let children;
|
|
16
16
|
let delayMs;
|
|
17
17
|
let rest;
|
|
@@ -51,10 +51,10 @@ function Announce(props) {
|
|
|
51
51
|
const hidden = t2 === undefined ? false : t2;
|
|
52
52
|
const politeness = t3 === undefined ? "polite" : t3;
|
|
53
53
|
const ref = useRef(null);
|
|
54
|
-
const
|
|
54
|
+
const previousAnnouncementText = useRef(null);
|
|
55
55
|
const savedAnnouncement = useRef(null);
|
|
56
56
|
let t4;
|
|
57
|
-
if ($[8] !== delayMs || $[9] !== hidden || $[10] !== politeness
|
|
57
|
+
if ($[8] !== delayMs || $[9] !== hidden || $[10] !== politeness) {
|
|
58
58
|
t4 = () => {
|
|
59
59
|
var _savedAnnouncement$cu;
|
|
60
60
|
const {
|
|
@@ -70,14 +70,10 @@ function Announce(props) {
|
|
|
70
70
|
if (!textContent) {
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
|
-
if (textContent === previousAnnouncementText) {
|
|
73
|
+
if (textContent === previousAnnouncementText.current) {
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
if (style.display === "none") {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (style.visibility === "hidden") {
|
|
76
|
+
if (!isVisible(element)) {
|
|
81
77
|
return;
|
|
82
78
|
}
|
|
83
79
|
(_savedAnnouncement$cu = savedAnnouncement.current) === null || _savedAnnouncement$cu === void 0 ? void 0 : _savedAnnouncement$cu.cancel();
|
|
@@ -87,34 +83,33 @@ function Announce(props) {
|
|
|
87
83
|
politeness,
|
|
88
84
|
delayMs
|
|
89
85
|
});
|
|
90
|
-
|
|
86
|
+
previousAnnouncementText.current = textContent;
|
|
91
87
|
};
|
|
92
88
|
$[8] = delayMs;
|
|
93
89
|
$[9] = hidden;
|
|
94
90
|
$[10] = politeness;
|
|
95
|
-
$[11] =
|
|
96
|
-
$[12] = t4;
|
|
91
|
+
$[11] = t4;
|
|
97
92
|
} else {
|
|
98
|
-
t4 = $[
|
|
93
|
+
t4 = $[11];
|
|
99
94
|
}
|
|
100
95
|
const announce = useEffectCallback(t4);
|
|
101
96
|
let t5;
|
|
102
|
-
if ($[
|
|
97
|
+
if ($[12] !== announce || $[13] !== announceOnShow) {
|
|
103
98
|
t5 = () => {
|
|
104
99
|
if (announceOnShow) {
|
|
105
100
|
announce();
|
|
106
101
|
}
|
|
107
102
|
};
|
|
108
|
-
$[
|
|
109
|
-
$[
|
|
110
|
-
$[
|
|
103
|
+
$[12] = announce;
|
|
104
|
+
$[13] = announceOnShow;
|
|
105
|
+
$[14] = t5;
|
|
111
106
|
} else {
|
|
112
|
-
t5 = $[
|
|
107
|
+
t5 = $[14];
|
|
113
108
|
}
|
|
114
109
|
useEffectOnce(t5);
|
|
115
110
|
let t6;
|
|
116
111
|
let t7;
|
|
117
|
-
if ($[
|
|
112
|
+
if ($[15] !== announce) {
|
|
118
113
|
t6 = () => {
|
|
119
114
|
const {
|
|
120
115
|
current: container
|
|
@@ -135,17 +130,17 @@ function Announce(props) {
|
|
|
135
130
|
};
|
|
136
131
|
};
|
|
137
132
|
t7 = [announce];
|
|
138
|
-
$[
|
|
139
|
-
$[
|
|
140
|
-
$[
|
|
133
|
+
$[15] = announce;
|
|
134
|
+
$[16] = t6;
|
|
135
|
+
$[17] = t7;
|
|
141
136
|
} else {
|
|
142
|
-
t6 = $[
|
|
143
|
-
t7 = $[
|
|
137
|
+
t6 = $[16];
|
|
138
|
+
t7 = $[17];
|
|
144
139
|
}
|
|
145
140
|
useEffect(t6, t7);
|
|
146
141
|
let t8;
|
|
147
142
|
let t9;
|
|
148
|
-
if ($[
|
|
143
|
+
if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
|
|
149
144
|
t8 = () => () => {
|
|
150
145
|
if (savedAnnouncement.current !== null) {
|
|
151
146
|
savedAnnouncement.current.cancel();
|
|
@@ -153,26 +148,26 @@ function Announce(props) {
|
|
|
153
148
|
}
|
|
154
149
|
};
|
|
155
150
|
t9 = [];
|
|
156
|
-
$[
|
|
157
|
-
$[
|
|
151
|
+
$[18] = t8;
|
|
152
|
+
$[19] = t9;
|
|
158
153
|
} else {
|
|
159
|
-
t8 = $[
|
|
160
|
-
t9 = $[
|
|
154
|
+
t8 = $[18];
|
|
155
|
+
t9 = $[19];
|
|
161
156
|
}
|
|
162
157
|
useEffect(t8, t9);
|
|
163
158
|
let t10;
|
|
164
|
-
if ($[
|
|
159
|
+
if ($[20] !== BaseComponent || $[21] !== children || $[22] !== rest) {
|
|
165
160
|
t10 = /*#__PURE__*/jsx(BaseComponent, {
|
|
166
161
|
...rest,
|
|
167
162
|
ref: ref,
|
|
168
163
|
children: children
|
|
169
164
|
});
|
|
170
|
-
$[
|
|
171
|
-
$[
|
|
172
|
-
$[
|
|
173
|
-
$[
|
|
165
|
+
$[20] = BaseComponent;
|
|
166
|
+
$[21] = children;
|
|
167
|
+
$[22] = rest;
|
|
168
|
+
$[23] = t10;
|
|
174
169
|
} else {
|
|
175
|
-
t10 = $[
|
|
170
|
+
t10 = $[23];
|
|
176
171
|
}
|
|
177
172
|
return t10;
|
|
178
173
|
}
|
|
@@ -186,4 +181,24 @@ function getTextContent(element) {
|
|
|
186
181
|
return value ? value.trim() : '';
|
|
187
182
|
}
|
|
188
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Determine if an element is visible (not hidden via `display: none` or
|
|
186
|
+
* `visibility: hidden`). Prefers the native `checkVisibility()` API when
|
|
187
|
+
* available and falls back to `getComputedStyle` for older browsers.
|
|
188
|
+
*/
|
|
189
|
+
function isVisible(element) {
|
|
190
|
+
if (typeof element.checkVisibility === 'function') {
|
|
191
|
+
return element.checkVisibility({
|
|
192
|
+
// `visibilityProperty` is the standard option name (Chrome 116+, Firefox
|
|
193
|
+
// 125+, Safari 17.4+); `checkVisibilityCSS` is the legacy Chromium name
|
|
194
|
+
// (Chrome 105+). Unknown options are ignored, so passing both ensures
|
|
195
|
+
// `visibility: hidden` is treated as not visible across all engines.
|
|
196
|
+
visibilityProperty: true,
|
|
197
|
+
checkVisibilityCSS: true
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
const style = window.getComputedStyle(element);
|
|
201
|
+
return style.display !== 'none' && style.visibility !== 'hidden';
|
|
202
|
+
}
|
|
203
|
+
|
|
189
204
|
export { Announce };
|
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared character counting
|
|
3
|
-
*
|
|
2
|
+
* Shared character counting helpers for text inputs with character limits.
|
|
3
|
+
* Provides the pure derivation used to render the counter and validation state.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
onScreenReaderAnnounce: (message: string) => void;
|
|
8
|
-
}
|
|
9
|
-
export declare class CharacterCounter {
|
|
10
|
-
private announceTimeout;
|
|
11
|
-
private callbacks;
|
|
12
|
-
private isInitialLoad;
|
|
13
|
-
constructor(callbacks: CharacterCounterCallbacks);
|
|
14
|
-
/**
|
|
15
|
-
* Update the character count based on current input value
|
|
16
|
-
*/
|
|
17
|
-
updateCharacterCount(currentLength: number, maxLength: number): void;
|
|
5
|
+
export declare const SCREEN_READER_DELAY = 500;
|
|
6
|
+
export interface CharacterCountState {
|
|
18
7
|
/**
|
|
19
|
-
*
|
|
8
|
+
* Number of characters remaining before the limit is reached, or the number of
|
|
9
|
+
* characters over the limit when it has been exceeded.
|
|
20
10
|
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
count: number;
|
|
12
|
+
/** Whether the current length exceeds the limit. */
|
|
13
|
+
isOverLimit: boolean;
|
|
14
|
+
/** Human readable description of the remaining or over count. */
|
|
15
|
+
message: string;
|
|
26
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Compute the character count state for a given length and limit. This is a pure
|
|
19
|
+
* function so the counter can be derived during render without component state.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getCharacterCountState(currentLength: number, maxLength: number): CharacterCountState;
|
|
27
22
|
//# sourceMappingURL=character-counter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"character-counter.d.ts","sourceRoot":"","sources":["../../src/utils/character-counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"character-counter.d.ts","sourceRoot":"","sources":["../../src/utils/character-counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,mBAAmB,MAAM,CAAA;AAEtC,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAA;IACb,oDAAoD;IACpD,WAAW,EAAE,OAAO,CAAA;IACpB,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,mBAAmB,CAmBpG"}
|
|
@@ -1,66 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared character counting
|
|
3
|
-
*
|
|
2
|
+
* Shared character counting helpers for text inputs with character limits.
|
|
3
|
+
* Provides the pure derivation used to render the counter and validation state.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const SCREEN_READER_DELAY = 500;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let message = '';
|
|
21
|
-
if (charactersRemaining >= 0) {
|
|
22
|
-
const characterText = charactersRemaining === 1 ? 'character' : 'characters';
|
|
23
|
-
message = `${charactersRemaining} ${characterText} remaining`;
|
|
24
|
-
this.callbacks.onCountUpdate(charactersRemaining, false, message);
|
|
25
|
-
} else {
|
|
26
|
-
const charactersOver = -charactersRemaining;
|
|
27
|
-
const characterText = charactersOver === 1 ? 'character' : 'characters';
|
|
28
|
-
message = `${charactersOver} ${characterText} over`;
|
|
29
|
-
this.callbacks.onCountUpdate(charactersOver, true, message);
|
|
30
|
-
}
|
|
31
|
-
if (!this.isInitialLoad) {
|
|
32
|
-
this.announceToScreenReader(message);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// After first update, set isInitialLoad to false
|
|
36
|
-
if (this.isInitialLoad) {
|
|
37
|
-
this.isInitialLoad = false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Announce character count to screen readers with debouncing
|
|
43
|
-
*/
|
|
44
|
-
announceToScreenReader(message) {
|
|
45
|
-
if (this.announceTimeout) {
|
|
46
|
-
clearTimeout(this.announceTimeout);
|
|
47
|
-
}
|
|
48
|
-
if (typeof window === 'undefined' || typeof window.setTimeout !== 'function') {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
this.announceTimeout = window.setTimeout(() => {
|
|
52
|
-
this.callbacks.onScreenReaderAnnounce(message);
|
|
53
|
-
}, SCREEN_READER_DELAY);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Clean up any pending timeouts
|
|
58
|
-
*/
|
|
59
|
-
cleanup() {
|
|
60
|
-
if (this.announceTimeout) {
|
|
61
|
-
clearTimeout(this.announceTimeout);
|
|
62
|
-
}
|
|
7
|
+
/**
|
|
8
|
+
* Compute the character count state for a given length and limit. This is a pure
|
|
9
|
+
* function so the counter can be derived during render without component state.
|
|
10
|
+
*/
|
|
11
|
+
function getCharacterCountState(currentLength, maxLength) {
|
|
12
|
+
const charactersRemaining = maxLength - currentLength;
|
|
13
|
+
if (charactersRemaining >= 0) {
|
|
14
|
+
const characterText = charactersRemaining === 1 ? 'character' : 'characters';
|
|
15
|
+
return {
|
|
16
|
+
count: charactersRemaining,
|
|
17
|
+
isOverLimit: false,
|
|
18
|
+
message: `${charactersRemaining} ${characterText} remaining`
|
|
19
|
+
};
|
|
63
20
|
}
|
|
21
|
+
const charactersOver = -charactersRemaining;
|
|
22
|
+
const characterText = charactersOver === 1 ? 'character' : 'characters';
|
|
23
|
+
return {
|
|
24
|
+
count: charactersOver,
|
|
25
|
+
isOverLimit: true,
|
|
26
|
+
message: `${charactersOver} ${characterText} over`
|
|
27
|
+
};
|
|
64
28
|
}
|
|
65
29
|
|
|
66
|
-
export {
|
|
30
|
+
export { SCREEN_READER_DELAY, getCharacterCountState };
|
package/package.json
CHANGED