Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid using aria-hidden on a focused element #451

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有了下面这个 div,第一个可以去掉了。

<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
Loading