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(js): allow body scroll when detached mode responsively disabled #1251

Merged
merged 3 commits into from
May 14, 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
34 changes: 34 additions & 0 deletions packages/autocomplete-js/src/__tests__/detached.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,38 @@ describe('detached', () => {
).toHaveAttribute('hidden');
});
});

test('removes aa-Detached when no longer matching', async () => {
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: createMatchMedia({ matches: true }),
});

const container = document.createElement('div');

document.body.appendChild(container);
const { update } = autocomplete<{ label: string }>({
container,
detachedMediaQuery: 'something',
});

const searchButton = container.querySelector<HTMLButtonElement>(
'.aa-DetachedSearchButton'
)!;

// Open detached overlay
searchButton.click();

await waitFor(() => expect(document.body).toHaveClass('aa-Detached'));

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: createMatchMedia({ matches: false }),
});

// schedule a render (normally this is done by the matchMedia listener, but that's not accessible here)
update({ detachedMediaQuery: 'something' });

await waitFor(() => expect(document.body).not.toHaveClass('aa-Detached'));
});
});
1 change: 1 addition & 0 deletions packages/autocomplete-js/src/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export function autocomplete<TItem extends BaseItem>(
return () => {
if (panelContainerElement.contains(panelElement)) {
panelContainerElement.removeChild(panelElement);
panelContainerElement.classList.remove('aa-Detached');
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
}
};
});
Expand Down