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: fixed VO and JAWS problem in FF and Safari #14156

Merged
merged 14 commits into from
Jul 13, 2023
Merged
35 changes: 19 additions & 16 deletions packages/react/src/components/ComposedModal/ComposedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,28 +305,30 @@ const ComposedModal = React.forwardRef<HTMLDivElement, ComposedModalProps>(
});

useEffect(() => {
const focusButton = (focusContainerElement) => {
if (focusContainerElement) {
const primaryFocusElement =
focusContainerElement.querySelector(selectorPrimaryFocus);
if (primaryFocusElement) {
primaryFocusElement.focus();
return;
}
if (button.current) {
button.current.focus();
}
const initialFocus = (focusContainerElement) => {
const containerElement = focusContainerElement || innerModal.current;
const primaryFocusElement = containerElement
? containerElement.querySelector(selectorPrimaryFocus)
: null;

if (primaryFocusElement) {
return primaryFocusElement;
}

return button && button.current;
};

if (!open) {
return;
}
const focusButton = (focusContainerElement) => {
const target = initialFocus(focusContainerElement);
if (target) {
target.focus();
}
};

if (innerModal.current) {
if (open && isOpen) {
focusButton(innerModal.current);
}
}, [open, selectorPrimaryFocus]);
}, [open, selectorPrimaryFocus, isOpen]);

return (
<div
Expand All @@ -345,6 +347,7 @@ const ComposedModal = React.forwardRef<HTMLDivElement, ComposedModalProps>(
aria-label={ariaLabel ? ariaLabel : generatedAriaLabel}
aria-labelledby={ariaLabelledBy}>
{/* Non-translatable: Focus-wrap code makes this `<button>` not actually read by screen readers */}

<button
type="button"
ref={startSentinel}
Expand Down