Skip to content

Commit

Permalink
fix: Avoid using aria-hidden on a focused element (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 authored Aug 9, 2024
1 parent 1ed5252 commit 2580d29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
8 changes: 3 additions & 5 deletions src/Dialog/Content/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ const Panel = React.forwardRef<ContentRef, PanelProps>((props, ref) => {

const sentinelStartRef = useRef<HTMLDivElement>();
const sentinelEndRef = useRef<HTMLDivElement>();
const entityRef = useRef<HTMLDivElement>();

React.useImperativeHandle(ref, () => ({
focus: () => {
entityRef.current?.focus({ preventScroll: true });
sentinelStartRef.current?.focus({ preventScroll: true });
},
changeActive: (next) => {
const { activeElement } = document;
Expand Down Expand Up @@ -157,13 +156,12 @@ const Panel = React.forwardRef<ContentRef, PanelProps>((props, ref) => {
onMouseDown={onMouseDown}
onMouseUp={onMouseUp}
>
<div tabIndex={0} ref={sentinelStartRef} style={sentinelStyle} aria-hidden="true" />
<div ref={entityRef} tabIndex={-1} style={entityStyle}>
<div ref={sentinelStartRef} tabIndex={0} style={entityStyle}>
<MemoChildren shouldUpdate={visible || forceRender}>
{modalRender ? modalRender(content) : content}
</MemoChildren>
</div>
<div tabIndex={0} ref={sentinelEndRef} style={sentinelStyle} aria-hidden="true" />
<div tabIndex={0} ref={sentinelEndRef} style={sentinelStyle} />
</div>
);
});
Expand Down
32 changes: 4 additions & 28 deletions tests/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ exports[`dialog add rootClassName should render correct 1`] = `
role="dialog"
style="width: 600px; height: 903px;"
>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
<div
style="outline: none;"
tabindex="-1"
tabindex="0"
>
<div
class="rc-dialog-content"
Expand All @@ -45,7 +40,6 @@ exports[`dialog add rootClassName should render correct 1`] = `
</div>
</div>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
Expand All @@ -71,14 +65,9 @@ exports[`dialog should render correct 1`] = `
class="rc-dialog"
role="dialog"
>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
<div
style="outline: none;"
tabindex="-1"
tabindex="0"
>
<div
class="rc-dialog-content"
Expand Down Expand Up @@ -108,7 +97,6 @@ exports[`dialog should render correct 1`] = `
</div>
</div>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
Expand All @@ -135,14 +123,9 @@ exports[`dialog should support classNames 1`] = `
role="dialog"
style="width: 600px; height: 903px;"
>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
<div
style="outline: none;"
tabindex="-1"
tabindex="0"
>
<div
class="rc-dialog-content custom-content"
Expand Down Expand Up @@ -177,7 +160,6 @@ exports[`dialog should support classNames 1`] = `
</div>
</div>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
Expand Down Expand Up @@ -206,14 +188,9 @@ exports[`dialog should support styles 1`] = `
role="dialog"
style="width: 600px; height: 903px;"
>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
<div
style="outline: none;"
tabindex="-1"
tabindex="0"
>
<div
class="rc-dialog-content"
Expand Down Expand Up @@ -252,7 +229,6 @@ exports[`dialog should support styles 1`] = `
</div>
</div>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
Expand Down

0 comments on commit 2580d29

Please sign in to comment.