Skip to content

Commit

Permalink
yourgov: Fix Add/Remove employee focus management… again (#1871)
Browse files Browse the repository at this point in the history
  • Loading branch information
stowball authored Nov 11, 2024
1 parent 3915667 commit 5f09ef1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/thick-sheep-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ag.ds-next/yourgov': minor
---

yourgov: Fix Add/Remove employee focus management… again.
28 changes: 18 additions & 10 deletions yourgov/components/FormMobileFoodVendorPermit/steps/FormStep7.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ export function FormStep7() {
const [showAddedEmployeeMessage, setShowAddedEmployeeMessage] = useState(
!!addedEmployee
);
useEffect(() => {
setShowAddedEmployeeMessage(!!addedEmployee);

if (addedEmployee) {
setTimeout(() => {
addedPageAlertRef.current?.focus();
}, 500);
}
}, [addedEmployee]);

const closeModal = () => {
setShowAddedEmployeeMessage(false);
Expand Down Expand Up @@ -124,6 +115,24 @@ export function FormStep7() {
});
};

useEffect(() => {
setShowAddedEmployeeMessage(!!addedEmployee);

if (addedEmployee) {
setTimeout(() => {
addedPageAlertRef.current?.focus();
}, 500);
}
}, [addedEmployee]);

useEffect(() => {
if (removedEmployee) {
setTimeout(() => {
removedPageAlertRef.current?.focus();
}, 500);
}
}, [removedEmployee]);

return (
<FormContainer
formIntroduction="Add your employee details."
Expand Down Expand Up @@ -232,7 +241,6 @@ export function FormStep7() {
</Button>
</ButtonGroup>
}
elementToFocusOnClose={removedPageAlertRef?.current}
isOpen={modalIsVisible}
onClose={closeModal}
title={`Are you sure you want to remove ${employeeToRemove?.firstName} ${employeeToRemove?.lastName} as an employee?`}
Expand Down

0 comments on commit 5f09ef1

Please sign in to comment.