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

[CHUX-295] Force ec-modal to trap focus #1910

Merged
merged 4 commits into from
Apr 5, 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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ebury/chameleon-components",
"version": "2.8.1",
"version": "2.8.2",
"main": "src/main.ts",
"sideEffects": false,
"author": "Ebury Team (http://labs.ebury.rocks/)",
Expand Down
16 changes: 16 additions & 0 deletions src/components/ec-modal/ec-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ describe('EcModal', () => {
expect(wrapper.element).toMatchSnapshot();
});

it('should remove focus trap activation interval on unmount', () => {
const wrapper = mountModal(
{ show: true },
{
slots: {
main: '<p>Before we can process your application we need you to upload your management accounts. You can do this now or leave it for later.</p>',
},
},
);

const clearIntervalSpy = vi.spyOn(global, 'clearInterval');
wrapper.unmount();

expect(clearIntervalSpy).toHaveBeenCalledTimes(1);
});

it('should render with custom attributes', () => {
const wrapper = mountModal({
show: true,
Expand Down
5 changes: 4 additions & 1 deletion src/components/ec-modal/ec-modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ function getFocusTrapOptions(): UseFocusTrapOptions {
return options;
}

const { deactivate } = useFocusTrap(focusTrapTarget, getFocusTrapOptions());
const { deactivate, activate } = useFocusTrap(focusTrapTarget, getFocusTrapOptions());
const focusTrapInterval = setInterval(() => activate(), 300);

watch(() => focusTrapTarget.value, (targetEl) => {
if (!targetEl) {
deactivate();
Expand Down Expand Up @@ -219,6 +221,7 @@ function onKeyUp(e: KeyboardEvent) {
}
onBeforeUnmount(() => {
document.removeEventListener('keyup', onKeyUp);
clearInterval(focusTrapInterval);
});

// modal footer
Expand Down
Loading