Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
refactor: reset zoom when opening a listbox on
Browse files Browse the repository at this point in the history
  small devices
  • Loading branch information
johanlahti committed Oct 10, 2023
1 parent e236b84 commit 236eda2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/sn-filter-pane/src/components/ListboxPopoverContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ const StyledPopover = styled(Popover, { shouldForwardProp: (p: string) => !['isS
} : {},
}));

function resetZoom() {
const viewportMetaTag = document.querySelector('meta[name="viewport"]');
if (viewportMetaTag instanceof HTMLMetaElement) {
viewportMetaTag.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
}
}

/**
* If a single resource is passed to this component a FoldedListbox is rendered.
* When the FoldedListbox is clicked, a Listbox is rendered in a Popover.
Expand All @@ -85,6 +92,10 @@ export const ListboxPopoverContainer = ({ resources, stores }: FoldedPopoverProp
const handleOpen = ({ event }: FoldedListboxClickEvent | { event: React.MouseEvent<HTMLButtonElement, MouseEvent> }) => {
if (event.currentTarget.contains(event.target as Node) && !constraints?.active) {
setPopoverOpen(true);
if (isSmallDevice) {
// Autofocus can cause the browser to zoom so we need to reset zoom.
resetZoom();
}
}
};
const handleClose = () => {
Expand Down

0 comments on commit 236eda2

Please sign in to comment.