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

Commit

Permalink
fix(sn-filter-pane): reset zoom for all scenarios (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanlahti committed Jan 17, 2024
1 parent 0df12ac commit e4dcc8c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { RenderTrackerService } from '../../services/render-tracker';
import useFocusListener from '../../hooks/use-focus-listener';
import findNextIndex from './find-next-index';
import { IEnv } from '../../types/types';
import resetZoom from '../../utils/reset-zoom';

const prepareRenderTracker = (listboxCount: number, renderTracker?: RenderTrackerService) => {
renderTracker?.setNumberOfListboxes(listboxCount);
Expand Down Expand Up @@ -116,6 +117,8 @@ function ListboxGrid({ stores }: { stores: IStores }) {
preventDefaultBehavior(event);
};

const handleFocus = sense?.isSmallDevice?.() ? () => resetZoom() : undefined;

useFocusListener(gridRef, keyboard);

const isRtl = options.direction === 'rtl';
Expand All @@ -141,7 +144,18 @@ function ListboxGrid({ stores }: { stores: IStores }) {
return (
<>
<ElementResizeListener onResize={dHandleResize.current} />
<Grid className="filter-pane-container" container onKeyDown={handleKeyDown} sx={{ flexDirection: isRtl ? 'row-reverse' : 'row' }} columns={columns?.length} ref={gridRef as unknown as () => HTMLDivElement} spacing={0} height='100%' overflow="hidden">
<Grid
className="filter-pane-container"
container
onKeyDown={handleKeyDown}
onFocus={handleFocus}
sx={{ flexDirection: isRtl ? 'row-reverse' : 'row' }}
columns={columns?.length}
ref={gridRef as unknown as () => HTMLObjectElement}
spacing={0}
height='100%'
overflow="hidden"
>

{!!columns?.length && columns?.map((column: IColumn, i: number) => (
<ColumnGrid key={i} widthPercent={100 / columns.length}>
Expand Down
11 changes: 11 additions & 0 deletions packages/sn-filter-pane/src/utils/reset-zoom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Run this on small devices to reset the zoom. Required when focusing
* an input field and the browser auto zooms the page. Browsers do not
* expose any API for handling this currently.
*/
export default 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';
}
}

0 comments on commit e4dcc8c

Please sign in to comment.