Skip to content

Commit 2580d29

Browse files
authored
fix: Avoid using aria-hidden on a focused element (#451)
1 parent 1ed5252 commit 2580d29

File tree

2 files changed

+7
-33
lines changed

2 files changed

+7
-33
lines changed

src/Dialog/Content/Panel.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ const Panel = React.forwardRef<ContentRef, PanelProps>((props, ref) => {
5555

5656
const sentinelStartRef = useRef<HTMLDivElement>();
5757
const sentinelEndRef = useRef<HTMLDivElement>();
58-
const entityRef = useRef<HTMLDivElement>();
5958

6059
React.useImperativeHandle(ref, () => ({
6160
focus: () => {
62-
entityRef.current?.focus({ preventScroll: true });
61+
sentinelStartRef.current?.focus({ preventScroll: true });
6362
},
6463
changeActive: (next) => {
6564
const { activeElement } = document;
@@ -157,13 +156,12 @@ const Panel = React.forwardRef<ContentRef, PanelProps>((props, ref) => {
157156
onMouseDown={onMouseDown}
158157
onMouseUp={onMouseUp}
159158
>
160-
<div tabIndex={0} ref={sentinelStartRef} style={sentinelStyle} aria-hidden="true" />
161-
<div ref={entityRef} tabIndex={-1} style={entityStyle}>
159+
<div ref={sentinelStartRef} tabIndex={0} style={entityStyle}>
162160
<MemoChildren shouldUpdate={visible || forceRender}>
163161
{modalRender ? modalRender(content) : content}
164162
</MemoChildren>
165163
</div>
166-
<div tabIndex={0} ref={sentinelEndRef} style={sentinelStyle} aria-hidden="true" />
164+
<div tabIndex={0} ref={sentinelEndRef} style={sentinelStyle} />
167165
</div>
168166
);
169167
});

tests/__snapshots__/index.spec.tsx.snap

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@ exports[`dialog add rootClassName should render correct 1`] = `
1818
role="dialog"
1919
style="width: 600px; height: 903px;"
2020
>
21-
<div
22-
aria-hidden="true"
23-
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
24-
tabindex="0"
25-
/>
2621
<div
2722
style="outline: none;"
28-
tabindex="-1"
23+
tabindex="0"
2924
>
3025
<div
3126
class="rc-dialog-content"
@@ -45,7 +40,6 @@ exports[`dialog add rootClassName should render correct 1`] = `
4540
</div>
4641
</div>
4742
<div
48-
aria-hidden="true"
4943
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
5044
tabindex="0"
5145
/>
@@ -71,14 +65,9 @@ exports[`dialog should render correct 1`] = `
7165
class="rc-dialog"
7266
role="dialog"
7367
>
74-
<div
75-
aria-hidden="true"
76-
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
77-
tabindex="0"
78-
/>
7968
<div
8069
style="outline: none;"
81-
tabindex="-1"
70+
tabindex="0"
8271
>
8372
<div
8473
class="rc-dialog-content"
@@ -108,7 +97,6 @@ exports[`dialog should render correct 1`] = `
10897
</div>
10998
</div>
11099
<div
111-
aria-hidden="true"
112100
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
113101
tabindex="0"
114102
/>
@@ -135,14 +123,9 @@ exports[`dialog should support classNames 1`] = `
135123
role="dialog"
136124
style="width: 600px; height: 903px;"
137125
>
138-
<div
139-
aria-hidden="true"
140-
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
141-
tabindex="0"
142-
/>
143126
<div
144127
style="outline: none;"
145-
tabindex="-1"
128+
tabindex="0"
146129
>
147130
<div
148131
class="rc-dialog-content custom-content"
@@ -177,7 +160,6 @@ exports[`dialog should support classNames 1`] = `
177160
</div>
178161
</div>
179162
<div
180-
aria-hidden="true"
181163
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
182164
tabindex="0"
183165
/>
@@ -206,14 +188,9 @@ exports[`dialog should support styles 1`] = `
206188
role="dialog"
207189
style="width: 600px; height: 903px;"
208190
>
209-
<div
210-
aria-hidden="true"
211-
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
212-
tabindex="0"
213-
/>
214191
<div
215192
style="outline: none;"
216-
tabindex="-1"
193+
tabindex="0"
217194
>
218195
<div
219196
class="rc-dialog-content"
@@ -252,7 +229,6 @@ exports[`dialog should support styles 1`] = `
252229
</div>
253230
</div>
254231
<div
255-
aria-hidden="true"
256232
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
257233
tabindex="0"
258234
/>

0 commit comments

Comments
 (0)