Skip to content

Commit

Permalink
fix(Export Modal): Focus moves to parent page (#6077)
Browse files Browse the repository at this point in the history
* fix(exportmodal): return focus to close button after submit

* fix(ExportModal): added aria-live attribute for alrt div

* fix(datagrid): remove screen reader update PR already there

* fix(ExportModal): update close button selector
  • Loading branch information
sangeethababu9223 committed Sep 24, 2024
1 parent dd7564d commit ef4bfa8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/ibm-products/src/components/ExportModal/ExportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import React, {
import PropTypes from 'prop-types';
import cx from 'classnames';
import { getDevtoolsProps } from '../../global/js/utils/devtools';
import { pkg } from '../../settings';
import { pkg, carbon } from '../../settings';
import { usePortalTarget } from '../../global/js/hooks/usePortalTarget';
import uuidv4 from '../../global/js/utils/uuidv4';

Expand Down Expand Up @@ -188,6 +188,7 @@ export let ExportModal = forwardRef(
}: React.PropsWithChildren<ExportModalProps>,
ref
) => {
const blockClass = `${pkg.prefix}--export-modal`;
const [name, setName] = useState('');
const [dirtyInput, setDirtyInput] = useState(false);
// by default (if it exists) use the first extension in the extension array
Expand All @@ -205,6 +206,15 @@ export let ExportModal = forwardRef(
}
}, [filename, preformattedExtensions, open]);

useEffect(() => {
if (successful) {
const button: HTMLButtonElement | null = document.querySelector(
`.${blockClass} .${carbon.prefix}--modal-close-button button`
);
button?.focus();
}
}, [successful, blockClass]);

const onNameChangeHandler = (evt) => {
setName(evt.target.value);
};
Expand Down Expand Up @@ -238,7 +248,6 @@ export let ExportModal = forwardRef(
return false;
};

const blockClass = `${pkg.prefix}--export-modal`;
const internalId = useRef(uuidv4());
const primaryButtonDisabled = loading || !name || hasInvalidExtension();
const submitted = loading || error || successful;
Expand Down

0 comments on commit ef4bfa8

Please sign in to comment.