diff --git a/photomap/frontend/static/css/grid-view.css b/photomap/frontend/static/css/grid-view.css index 3aa19199..0d66ad3e 100644 --- a/photomap/frontend/static/css/grid-view.css +++ b/photomap/frontend/static/css/grid-view.css @@ -8,14 +8,18 @@ height: calc(var(--visible-viewport-height, 100dvh) - var(--grid-top-reserve)); } -/* In the phone layout the badge is in the top sheet, which covers the grid - only by its handle unless the user pulls it open to seek. The bottom sheet +/* With the badge in the top sheet, the sheet covers the grid only by its + handle unless the user pulls it open to seek. */ +.top-sheet #gridViewSwiper { + --grid-top-reserve: calc(var(--top-sheet-peek) + 6px); +} + +/* In the phone layout the bottom sheet is another matter: open, it is two rows of buttons tall, and Swiper divides the container's height between the grid rows, so the container has to stop above it. --bottom-sheet-height follows the sheet as it opens and closes (mobile-sheets.js), and grid-view.js re-counts the rows when it does. */ .mobile-sheets #gridViewSwiper { - --grid-top-reserve: calc(var(--top-sheet-peek) + 6px); height: calc( var(--visible-viewport-height, 100dvh) - var(--grid-top-reserve) - var(--bottom-sheet-height, 0px) - 6px ); @@ -28,7 +32,7 @@ html.mobile-sheets:is(:fullscreen, :-webkit-full-screen) #gridViewSwiper { height: var(--visible-viewport-height, 100dvh); } -/* The badge is hidden in fullscreen (seek-slider.css), so give the row back. */ +/* The badge and the top sheet are hidden in fullscreen, so give the row back. */ :is(:fullscreen, :-webkit-full-screen) #gridViewSwiper { --grid-top-reserve: 0px; } diff --git a/photomap/frontend/static/css/mobile-sheets.css b/photomap/frontend/static/css/mobile-sheets.css index f685e18a..bd743b88 100644 --- a/photomap/frontend/static/css/mobile-sheets.css +++ b/photomap/frontend/static/css/mobile-sheets.css @@ -7,7 +7,11 @@ holds the metadata drawer's contents below the panels: at the expanded stop only their title row shows, and its third, "details" stop opens them. - Everything here is keyed off html.mobile-sheets, set from the media query in + The top sheet has its own switch, html.top-sheet (main.html's + ), which is currently on everywhere: tablets + and desktop browsers get the top sheet too, but not the bottom one. + + Everything else here is keyed off html.mobile-sheets, set from the media query in main.html's , and the sheet states off html[data-top-sheet] / html[data-bottom-sheet]. This file loads after the panel and slider stylesheets, so at equal specificity its rules win. */ @@ -36,7 +40,8 @@ /* ----- Common to both sheets ----- */ -.mobile-sheets .mobile-sheet { +.mobile-sheets #panelStackContainer, +.top-sheet #topSheetContainer { position: fixed; left: 0; right: 0; @@ -51,15 +56,18 @@ pointer-events: auto; } -.mobile-sheets.sheets-ready .mobile-sheet { +.mobile-sheets.sheets-ready #panelStackContainer, +.top-sheet.sheets-ready #topSheetContainer { transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); } -.mobile-sheets.sheets-ready .mobile-sheet.sheet-dragging { +.mobile-sheets.sheets-ready #panelStackContainer.sheet-dragging, +.top-sheet.sheets-ready #topSheetContainer.sheet-dragging { transition: none; } -.mobile-sheets .sheet-handle { +.mobile-sheets #bottomSheetHandle, +.top-sheet #topSheetHandle { display: flex; align-items: center; justify-content: center; @@ -74,7 +82,8 @@ } /* The pill. */ -.mobile-sheets .sheet-handle::before { +.mobile-sheets #bottomSheetHandle::before, +.top-sheet #topSheetHandle::before { content: ""; width: 40px; height: 5px; @@ -82,14 +91,17 @@ background: var(--sheet-handle-color); } -.mobile-sheets .sheet-handle:focus-visible { +.mobile-sheets #bottomSheetHandle:focus-visible, +.top-sheet #topSheetHandle:focus-visible { outline: 2px solid #fff; outline-offset: -2px; } -/* Hidden with the rest of the controls in fullscreen. (:is() keeps an unknown - prefixed pseudo-class from dropping the rule; see seek-slider.css.) */ -html.mobile-sheets:is(:fullscreen, :-webkit-full-screen) .mobile-sheet { +/* Hidden with the rest of the controls in fullscreen, on every screen: the + whole top sheet goes, handle and progress strip included. (:is() keeps an + unknown prefixed pseudo-class from dropping the rule; see seek-slider.css.) */ +html.mobile-sheets:is(:fullscreen, :-webkit-full-screen) #panelStackContainer, +html.top-sheet:is(:fullscreen, :-webkit-full-screen) #topSheetContainer { display: none !important; } @@ -321,7 +333,7 @@ html.mobile-sheets[data-bottom-sheet="expanded"] #panelStackContainer { /* ----- Top sheet: album badge and seek slider ----- */ -.mobile-sheets #topSheetContainer { +.top-sheet #topSheetContainer { top: 0; /* Under the semantic map (1000), as the badge always was, so the map's titlebar is not covered; above the photo and grid. */ @@ -329,60 +341,82 @@ html.mobile-sheets[data-bottom-sheet="expanded"] #panelStackContainer { display: flex; flex-direction: column; align-items: stretch; - padding: 6px 0 0; + padding: 4px 0 0; border-radius: 0 0 14px 14px; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35); } -html.mobile-sheets[data-top-sheet="collapsed"] #topSheetContainer { +html.top-sheet[data-top-sheet="collapsed"] #topSheetContainer { transform: translateY(calc(-100% + var(--top-sheet-peek))); } /* The badge keeps its own pill (it carries the cluster colour) but sits in the - sheet instead of floating over the corner of the photo. */ -.mobile-sheets .fixed-score-display { + sheet instead of floating over the corner of the photo. Its two lines become + one, the slide counter ahead of the reindex button and album pulldown, to + keep the sheet short. */ +.top-sheet .fixed-score-display { position: static; align-self: flex-start; max-width: calc(100% - 16px); margin: 0 8px; box-shadow: none; order: 1; + flex-direction: row; + align-items: center; + gap: 8px; +} + +.top-sheet .album-badge-row { + flex: 0 1 auto; +} + +.top-sheet .fixed-score-display #scoreText { + order: -1; + flex: 0 1 auto; + padding: 2px 4px; + border-radius: 8px; +} + +/* A selected cluster colours the slide count and cluster name only + (score-display.js), as a pill of their own. */ +.top-sheet .fixed-score-display #scoreText.cluster-colored { + padding: 2px 8px; } /* The slider gets the full width of the sheet, under the badge. seek-slider.js leaves its left edge alone in this layout. Room is left at the sides for the end tick labels, which centre on the slider's ends, and below for the tick row, which hangs under the slider. */ -.mobile-sheets .score-slider-row { +.top-sheet .score-slider-row { position: static; left: auto; right: auto; order: 2; - margin: 10px 0 0; - padding: 0 32px 34px; + margin: 0; + padding: 0 32px 26px; transition: none; } -.mobile-sheets .slider-with-ticks-container { +.top-sheet .slider-with-ticks-container { min-width: 0; } /* Drag the thumb, not the sheet: make the slider a comfortable target. */ -.mobile-sheets .slide-seek-slider { +.top-sheet .slide-seek-slider { height: 28px; } /* No caption beside the slider, and no hover zone: the sheet opens and closes the slider here, and the zone, which hangs 20px below the slider row, would sit over the handle and swallow taps meant for it. */ -.mobile-sheets .context-label, -.mobile-sheets .slider-hover-zone { +.top-sheet .context-label, +.top-sheet .slider-hover-zone { display: none; } /* Ten date labels do not fit across a phone held upright; show every other. */ @media (max-width: 600px) { - .mobile-sheets .slider-tick:nth-child(even) .slider-tick-label { + .top-sheet .slider-tick:nth-child(even) .slider-tick-label { visibility: hidden; } } @@ -390,7 +424,7 @@ html.mobile-sheets[data-top-sheet="collapsed"] #topSheetContainer { /* The progress strip is what remains of the slider when the sheet is collapsed: it sits on the sheet's bottom edge, above the handle, and is part of the target that opens the sheet rather than a hover target of its own. */ -.mobile-sheets .slider-hover-strip { +.top-sheet .slider-hover-strip { position: static; order: 3; flex: 0 0 4px; @@ -399,7 +433,7 @@ html.mobile-sheets[data-top-sheet="collapsed"] #topSheetContainer { pointer-events: none; } -.mobile-sheets #topSheetHandle { +.top-sheet #topSheetHandle { order: 4; height: calc(var(--top-sheet-peek) - 4px); } diff --git a/photomap/frontend/static/javascript/events.js b/photomap/frontend/static/javascript/events.js index 53a96ca0..5e46a0ab 100644 --- a/photomap/frontend/static/javascript/events.js +++ b/photomap/frontend/static/javascript/events.js @@ -214,8 +214,10 @@ window.addEventListener("slideshowStartRequested", async () => { }); function setupAccessibility() { - // Disable tabbing on buttons to prevent focus issues - document.querySelectorAll("button").forEach((btn) => (btn.tabIndex = -1)); + // Disable tabbing on buttons to prevent focus issues. The sheet handles stay + // tabbable: a collapsed top sheet makes the album pulldown inside it inert, + // and its handle is then the keyboard's only way to it. + document.querySelectorAll("button:not(.sheet-handle)").forEach((btn) => (btn.tabIndex = -1)); // Handle radio button accessibility document.querySelectorAll('input[type="radio"]').forEach((rb) => { diff --git a/photomap/frontend/static/javascript/metadata-drawer.js b/photomap/frontend/static/javascript/metadata-drawer.js index de26202d..9d3e8add 100644 --- a/photomap/frontend/static/javascript/metadata-drawer.js +++ b/photomap/frontend/static/javascript/metadata-drawer.js @@ -17,6 +17,7 @@ import { applyRefTarget } from "./invoke-ref-target.js"; import { closeSheetDetails, isMobileSheetsMode, + isTopSheetMode, setSheetState, SHEET_DETAILS, sheetState, @@ -642,7 +643,7 @@ function drawerRestingTop() { // In the phone layout the badge rides in the top sheet, and measuring it // mid-slide would catch the sheet part-way. Clear the sheet in the state it // is settling to instead; it reports a change whenever that moves. - if (isMobileSheetsMode()) { + if (isTopSheetMode()) { return Math.round(sheetVisibleHeight("top") + DRAWER_TOP_GAP); } const badge = document.getElementById("fixedScoreDisplay"); diff --git a/photomap/frontend/static/javascript/mobile-sheets.js b/photomap/frontend/static/javascript/mobile-sheets.js index cd853f29..bc4c192f 100644 --- a/photomap/frontend/static/javascript/mobile-sheets.js +++ b/photomap/frontend/static/javascript/mobile-sheets.js @@ -20,6 +20,13 @@ // An inline script in main.html's
sets all three before first paint; // this module keeps them current afterwards. // +// The top sheet has a switch of its own: the media query in +// and the `top-sheet` class on . It is +// currently "all", so the badge and slider sit in the top sheet on every +// screen, tablets and desktop browsers included, while the bottom sheet (and +// the details in it) is still for phones only. Wherever the phone layout is on +// the top sheet must be too: its rules lean on --top-sheet-peek. +// // Listeners learn about changes from a `mobileSheetChanged` window event, // detail { sheet: "top" | "bottom", state, expanded, mobile }, where state is // "collapsed", "expanded" or (bottom only) "details", and expanded is true for @@ -28,6 +35,8 @@ const FALLBACK_QUERY = "(max-width: 600px), (max-height: 500px) and (pointer: coarse)"; const MODE_CLASS = "mobile-sheets"; +const TOP_FALLBACK_QUERY = "all"; +const TOP_MODE_CLASS = "top-sheet"; const DRAGGING_CLASS = "sheet-dragging"; const BOTTOM_STATE_KEY = "bottomSheetState"; @@ -70,7 +79,23 @@ export function isMobileSheetsMode() { return document.documentElement.classList.contains(MODE_CLASS); } -// mobile-sheets.css hides both sheets while the page is fullscreen. +/** The media query that puts the badge and slider in the top sheet. */ +export function topSheetQuery() { + const meta = document.querySelector('meta[name="top-sheet-query"]'); + return meta?.content || TOP_FALLBACK_QUERY; +} + +/** Are the badge and seek slider in the top sheet? */ +export function isTopSheetMode() { + return document.documentElement.classList.contains(TOP_MODE_CLASS); +} + +/** Is the named sheet's layout in effect? */ +function sheetModeActive(name) { + return name === "top" ? isTopSheetMode() : isMobileSheetsMode(); +} + +// mobile-sheets.css hides both sheets, whole, while the page is fullscreen. function sheetsHiddenByFullscreen() { return Boolean(document.fullscreenElement || document.webkitFullscreenElement); } @@ -148,6 +173,11 @@ class Sheet { this.onScrollerTouchMove = this.onScrollerTouchMove.bind(this); } + /** Is this sheet's layout in effect? */ + active() { + return sheetModeActive(this.name); + } + /** "collapsed", "expanded" or, for a sheet with details, "details". */ get state() { const value = document.documentElement.dataset[this.attribute]; @@ -184,7 +214,7 @@ class Sheet { * the details under their title row, which hang below the window there. */ detailsOffset() { - if (!this.details || !isMobileSheetsMode() || !this.details.slot.contains(this.details.banner)) { + if (!this.details || !this.active() || !this.details.slot.contains(this.details.banner)) { return 0; } const { slot } = this.details; @@ -221,7 +251,7 @@ class Sheet { * expanded height: what is under the sheet does not reflow as it opens. */ visibleHeight() { - if (!isMobileSheetsMode() || sheetsHiddenByFullscreen()) { + if (!this.active() || sheetsHiddenByFullscreen()) { return 0; } if (!this.expanded) { @@ -236,6 +266,10 @@ class Sheet { this.element.addEventListener("pointerup", this.onPointerUp); this.element.addEventListener("pointercancel", this.onPointerCancel); this.element.addEventListener("click", this.onClick); + // The handle is the keyboard's way in (events.js leaves it in the tab + // order, unlike other buttons), but a mouse press should not leave focus + // on it for the next Space or Enter to land there. + this.handle.addEventListener("mousedown", (event) => event.preventDefault()); if (this.details) { const scroller = this.details.banner; scroller.addEventListener("touchstart", this.onScrollerTouchStart, { passive: true }); @@ -288,7 +322,8 @@ class Sheet { sheet: this.name, state, expanded: state !== SHEET_COLLAPSED, - mobile: isMobileSheetsMode(), + // Whether this sheet's layout is in effect. + mobile: this.active(), }, }) ); @@ -314,7 +349,7 @@ class Sheet { * slid out of view, and say on the handle which way it goes. */ syncAccessibility() { - const mobile = isMobileSheetsMode(); + const mobile = this.active(); const state = this.state; const hidden = mobile && state === SHEET_COLLAPSED; for (const child of this.element.children) { @@ -351,7 +386,7 @@ class Sheet { } onPointerDown(event) { - if (!isMobileSheetsMode() || !event.isPrimary) { + if (!this.active() || !event.isPrimary) { return; } if (event.pointerType === "mouse" && event.button !== 0) { @@ -547,7 +582,7 @@ class Sheet { } onClick(event) { - if (!isMobileSheetsMode()) { + if (!this.active()) { return; } const state = this.state; @@ -578,7 +613,7 @@ function publishSheetHeights() { const mobile = isMobileSheetsMode(); for (const sheet of Object.values(sheets)) { const property = `--${sheet.name}-sheet-height`; - if (mobile) { + if (sheet.active()) { root.style.setProperty(property, `${Math.round(sheet.visibleHeight())}px`); } else { root.style.removeProperty(property); @@ -624,7 +659,7 @@ export function sheetVisibleHeight(name) { * @param {"top"|"bottom"} name */ export function sheetPeekHeight(name) { - if (!isMobileSheetsMode()) { + if (!sheetModeActive(name)) { return 0; } return sheets[name]?.peekHeight() ?? 0; @@ -641,7 +676,7 @@ export function sheetState(name) { * for, when fullscreen ends. */ export function setSheetState(name, state) { - if (isMobileSheetsMode() && !sheetsHiddenByFullscreen()) { + if (sheetModeActive(name) && !sheetsHiddenByFullscreen()) { sheets[name]?.setState(state); } } @@ -659,6 +694,15 @@ export function setSheetExpanded(name, expanded) { setSheetState(name, expanded ? SHEET_EXPANDED : SHEET_COLLAPSED); } +/** Reset a sheet whose layout just switched on or off. */ +function resetSheetForMode(sheet) { + // A drag cannot survive the layout changing under it. + sheet.drag = null; + sheet.touchGate = null; + sheet.element.classList.remove(DRAGGING_CLASS); + sheet.element.style.transform = ""; +} + function applyMode(mobile) { const root = document.documentElement; const wasMobile = root.classList.contains(MODE_CLASS); @@ -666,12 +710,8 @@ function applyMode(mobile) { if (mobile === wasMobile) { return; } - // A drag cannot survive the layout changing under it. for (const sheet of Object.values(sheets)) { - sheet.drag = null; - sheet.touchGate = null; - sheet.element.classList.remove(DRAGGING_CLASS); - sheet.element.style.transform = ""; + resetSheetForMode(sheet); } placeDetails(mobile); // The slider row is only ever opened by the user; coming back into the @@ -686,6 +726,19 @@ function applyMode(mobile) { } } +function applyTopMode(topMode) { + const root = document.documentElement; + const was = root.classList.contains(TOP_MODE_CLASS); + root.classList.toggle(TOP_MODE_CLASS, topMode); + const sheet = sheets.top; + if (topMode === was || !sheet) { + return; + } + resetSheetForMode(sheet); + root.dataset.topSheet = SHEET_COLLAPSED; + sheet.setState(SHEET_COLLAPSED, { force: true }); +} + /** Find the sheets in the page and start following the media query. */ export function initializeMobileSheets() { const root = document.documentElement; @@ -724,12 +777,15 @@ export function initializeMobileSheets() { const query = window.matchMedia?.(mobileSheetsQuery()); const mobile = Boolean(query?.matches); root.classList.toggle(MODE_CLASS, mobile); + const topQuery = window.matchMedia?.(topSheetQuery()); + root.classList.toggle(TOP_MODE_CLASS, Boolean(topQuery?.matches)); placeDetails(mobile); for (const sheet of Object.values(sheets)) { sheet.syncAccessibility(); } publishSheetHeights(); query?.addEventListener?.("change", (event) => applyMode(event.matches)); + topQuery?.addEventListener?.("change", (event) => applyTopMode(event.matches)); // Heights change with rotation and with what the sheets hold (the panel // labels can be switched off; a search changes the badge). diff --git a/photomap/frontend/static/javascript/score-display.js b/photomap/frontend/static/javascript/score-display.js index 2b82b1a2..56b0ebb4 100644 --- a/photomap/frontend/static/javascript/score-display.js +++ b/photomap/frontend/static/javascript/score-display.js @@ -1,6 +1,7 @@ // score-display.js // This file manages the score display functionality, showing and hiding the score overlay. import { getClusterLabelInfo, SHOW_CLUSTER_LABELS_IN_BADGES } from "./cluster-utils.js"; +import { isTopSheetMode } from "./mobile-sheets.js"; import { isColorLight } from "./utils.js"; // Utility function to check if a color is light // Star SVG icons for favorites display @@ -22,6 +23,16 @@ export class ScoreDisplay { // in, so it cannot be re-rendered when the labels change underneath it; // these can. Null whenever the pill is showing something else. this.lastClusterArgs = null; + // The cluster colour the badge is showing, or null; see applyColors. + this.currentColor = null; + + // Which element carries the cluster colour depends on whether the badge + // is in the top sheet; recolour if that changes under a shown badge. + window.addEventListener("mobileSheetChanged", (event) => { + if (event.detail?.sheet === "top" && this.isVisible) { + this.applyColors(this.currentColor); + } + }); // Set up click listener for the star icon (deferred until DOM is ready) if (document.readyState === "loading") { @@ -134,8 +145,7 @@ export class ScoreDisplay { this.scoreElement.style.display = "flex"; this.scoreElement.classList.add("visible"); this.scoreElement.classList.remove("hidden"); - this.scoreElement.style.backgroundColor = `rgba(0, 0, 0, ${this.opacity})`; // Default background color - this.scoreElement.style.color = "#fff"; // Default text color + this.applyColors(null); this.isVisible = true; this.dispatchContentChangedEvent(); } @@ -155,8 +165,7 @@ export class ScoreDisplay { this.scoreElement.style.display = "flex"; this.scoreElement.classList.add("visible"); this.scoreElement.classList.remove("hidden"); - this.scoreElement.style.backgroundColor = `rgba(0, 0, 0, ${this.opacity})`; // Default background color - this.scoreElement.style.color = "#fff"; // Default text color + this.applyColors(null); this.isVisible = true; this.dispatchContentChangedEvent(); } @@ -214,18 +223,43 @@ export class ScoreDisplay { this.isVisible = true; if (color) { - this.scoreElement.style.backgroundColor = color; this.scoreElement.style.opacity = this.opacity; - if (isColorLight(color)) { - this.scoreElement.style.color = "#000"; // Dark text for light background - } else { - this.scoreElement.style.color = "#fff"; // Light text for dark background - } + this.applyColors(color); } this.dispatchContentChangedEvent(); } } + /** + * Colour the badge for a cluster, or back to its default dark pill (null). + * With the badge in the top sheet the cluster colour goes on the slide + * count and cluster text alone (a pill of its own, mobile-sheets.css), and + * the album pulldown beside it stays on the badge's dark background. + * @param {string|null} clusterColor + */ + applyColors(clusterColor) { + this.currentColor = clusterColor || null; + const defaultBackground = `rgba(0, 0, 0, ${this.opacity})`; + const textColor = clusterColor && isColorLight(clusterColor) ? "#000" : "#fff"; + const inSheet = isTopSheetMode(); + const pill = inSheet ? this.scoreText : this.scoreElement; + if (inSheet) { + this.scoreElement.style.backgroundColor = defaultBackground; + this.scoreElement.style.color = "#fff"; + } else if (this.scoreText) { + this.scoreText.style.backgroundColor = ""; + this.scoreText.style.color = ""; + } + if (!pill) { + return; + } + pill.style.backgroundColor = clusterColor || (inSheet ? "" : defaultBackground); + pill.style.color = clusterColor ? textColor : inSheet ? "" : "#fff"; + if (this.scoreText) { + this.scoreText.classList.toggle("cluster-colored", inSheet && Boolean(clusterColor)); + } + } + hide() { this.scoreElement.classList.add("hidden"); this.scoreElement.classList.remove("visible"); diff --git a/photomap/frontend/static/javascript/seek-slider.js b/photomap/frontend/static/javascript/seek-slider.js index e17523cc..e68004bd 100644 --- a/photomap/frontend/static/javascript/seek-slider.js +++ b/photomap/frontend/static/javascript/seek-slider.js @@ -1,7 +1,7 @@ import { backStack } from "./back-stack.js"; import { bookmarkManager } from "./bookmarks.js"; import { scoreDisplay } from "./score-display.js"; -import { isMobileSheetsMode } from "./mobile-sheets.js"; +import { isTopSheetMode } from "./mobile-sheets.js"; import { getCurrentSlideIndex, slideState } from "./slide-state.js"; import { state } from "./state.js"; import { debounce } from "./utils.js"; @@ -143,7 +143,7 @@ class SeekSlider { } // In the phone layout the slider has its own full-width row under the // badge (mobile-sheets.css); an inline left would squeeze it back beside it. - if (isMobileSheetsMode()) { + if (isTopSheetMode()) { this.scoreSliderRow.style.left = ""; this.hoverStrip.style.left = ""; return; diff --git a/photomap/frontend/templates/main.html b/photomap/frontend/templates/main.html index a72e15d3..339ebad7 100644 --- a/photomap/frontend/templates/main.html +++ b/photomap/frontend/templates/main.html @@ -12,6 +12,9 @@ slider fold into sheets that slide in from the top and bottom edges (mobile-sheets.js). Narrow windows, and phones held sideways. --> + + @@ -22,6 +25,10 @@ if (meta && window.matchMedia && window.matchMedia(meta.content).matches) { root.classList.add("mobile-sheets"); } + var topMeta = document.querySelector('meta[name="top-sheet-query"]'); + if (window.matchMedia && window.matchMedia(topMeta ? topMeta.content : "all").matches) { + root.classList.add("top-sheet"); + } var bottom = "expanded"; try { if (localStorage.getItem("bottomSheetState") === "collapsed") { diff --git a/tests/frontend/metadata-drawer-sheet.test.js b/tests/frontend/metadata-drawer-sheet.test.js index d78ecdaa..0d159712 100644 --- a/tests/frontend/metadata-drawer-sheet.test.js +++ b/tests/frontend/metadata-drawer-sheet.test.js @@ -16,6 +16,7 @@ const closeSheetDetails = jest.fn(() => { jest.unstable_mockModule("../../photomap/frontend/static/javascript/mobile-sheets.js", () => ({ isMobileSheetsMode: () => mobile, + isTopSheetMode: () => mobile, setSheetState, closeSheetDetails, sheetState: () => bottomState, diff --git a/tests/frontend/mobile-sheets.test.js b/tests/frontend/mobile-sheets.test.js index 029ebcd5..6273cdb7 100644 --- a/tests/frontend/mobile-sheets.test.js +++ b/tests/frontend/mobile-sheets.test.js @@ -39,18 +39,25 @@ function drag(target, y0, y1, { steps = 10, duration = 400, release = true, kind } } +// The phone layout's query, and the top sheet's own ("all" when main.html's +// is absent, as it is here). +const TOP_QUERY = "all"; let queryListeners; +let topQueryListeners; let queryMatches; +let topQueryMatches; -function installMatchMedia(matches) { +function installMatchMedia(matches, topMatches = true) { queryMatches = matches; + topQueryMatches = topMatches; queryListeners = []; + topQueryListeners = []; window.matchMedia = jest.fn((query) => ({ media: query, get matches() { - return queryMatches; + return query === TOP_QUERY ? topQueryMatches : queryMatches; }, - addEventListener: (type, listener) => queryListeners.push(listener), + addEventListener: (type, listener) => (query === TOP_QUERY ? topQueryListeners : queryListeners).push(listener), removeEventListener: jest.fn(), })); } @@ -60,6 +67,11 @@ function flipQuery(matches) { queryListeners.forEach((listener) => listener({ matches })); } +function flipTopQuery(matches) { + topQueryMatches = matches; + topQueryListeners.forEach((listener) => listener({ matches })); +} + function buildDom() { document.body.innerHTML = `