diff --git a/packages/sn-filter-pane/src/components/ListboxPopoverContainer.tsx b/packages/sn-filter-pane/src/components/ListboxPopoverContainer.tsx index bc300720..2ca374e0 100644 --- a/packages/sn-filter-pane/src/components/ListboxPopoverContainer.tsx +++ b/packages/sn-filter-pane/src/components/ListboxPopoverContainer.tsx @@ -26,13 +26,21 @@ const popoverPaperProps = (selectedResource: boolean, isSmallDevice:boolean, sta } return { style: { - height: selectedResource ? calcHeight : undefined, - width: isSmallDevice ? '100%' : '234px', overflowX: 'hidden', overflowY: selectedResource ? 'hidden' : 'auto', backgroundColor, - maxWidth: isSmallDevice ? '100%' : 'calc(100% - 32px)', - maxHeight: isSmallDevice ? '100%' : 'calc(100% - 32px)', + ...(isSmallDevice ? { + width: '100%', + height: '100%', + maxWidth: '100%', + maxHeight: '100%', + } + : { + height: selectedResource ? calcHeight : undefined, + width: '234px', + maxWidth: 'calc(100% - 32px)', + maxHeight: 'calc(100% - 32px)', + }), }, }; }; @@ -51,6 +59,21 @@ const StyledDiv = styled('div')(() => ({ paddingBottom: '0px', })); +const StyledPopover = styled(Popover, { shouldForwardProp: (p: string) => !['isSmallDevice'].includes(p) })(({ isSmallDevice }: { isSmallDevice: boolean }) => ({ + '& .MuiPopover-paper': isSmallDevice ? { + // Override the top, left so the popover won't irrevocably go outside the viewport. + top: '0px !important', + left: '0px !important', + } : {}, +})); + +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. @@ -71,6 +94,10 @@ export const ListboxPopoverContainer = ({ resources, stores }: FoldedPopoverProp const handleOpen = ({ event }: FoldedListboxClickEvent | { event: React.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 = () => { @@ -211,17 +238,20 @@ export const ListboxPopoverContainer = ({ resources, stores }: FoldedPopoverProp {isSingle ? : } - } - + ); };