Extend the expanded mobile sheet up to the search field
CI / Lint (pull_request) Successful in 56s
CI / Test (pull_request) Successful in 1m27s
Release Drafter / Update release notes draft (pull_request) Successful in 16s

The tallest detent now fills the viewport down from the top of the search
field, so a fully expanded sheet covers the search field and avatar while
leaving that little strip visible above.

- DETENT_FRACTIONS.expanded is now the whole sheet; the sheet height is the
  viewport minus a top gap (replacing the 0.92 fraction cap).
- The modifier measures that gap from the search field, relative to the sheet's
  container (the viewport top is not the app's top), falling back to 8px.
- Update the sheet-detents unit test and read the real --sheet-height in the
  stacked-sheets acceptance test.
This commit is contained in:
raucao committed 2026-11-30 18:08:02 +04:00
1 parent fabf2ffa50
commit 64d26951d4
4 files changed
+48 -27

No files matched your search

+22 -1
View File
@@ -33,6 +33,10 @@ const HANDLE_SELECTOR = '.sheet-handle, .sidebar-header';
const FORM_SELECTOR = 'input, select, textarea';
const HEADER_CONTROL_SELECTOR = 'button, a';
// Fallback strip kept above a fully expanded sheet when the search field can't
// be measured. The mobile header pads the search form down by 0.5rem.
const DEFAULT_SHEET_TOP_GAP = 8;
export default class BottomSheetModifier extends Modifier {
@service mapUi;
@service router;
@@ -300,7 +304,7 @@ export default class BottomSheetModifier extends Modifier {
// listener also fires when the iOS keyboard opens, and reading innerHeight
// there keeps the measurement identical so the sheet does not collapse.
this.viewportHeight = window.innerHeight;
this.sheetHeight = computeSheetHeight(this.viewportHeight);
this.sheetHeight = computeSheetHeight(this.viewportHeight, this.topGap());
this.layout = computeDetentLayout({
viewportHeight: this.viewportHeight,
sheetHeight: this.sheetHeight,
@@ -308,6 +312,23 @@ export default class BottomSheetModifier extends Modifier {
this.element.style.setProperty('--sheet-height', `${this.sheetHeight}px`);
}
// The strip of viewport kept visible above a fully expanded sheet: the top of
// the search field, so the sheet reaches up to (and covers) the search field
// and avatar while leaving that little space above. Measured relative to the
// sheet's container, since the viewport top is not the app's top (e.g. in
// tests the app sits below the QUnit results).
topGap() {
const searchForm = document.querySelector('.search-form');
const container = this.element?.parentElement;
if (searchForm && container) {
const gap =
searchForm.getBoundingClientRect().top -
container.getBoundingClientRect().top;
if (gap > 0 && gap < 200) return Math.round(gap);
}
return DEFAULT_SHEET_TOP_GAP;
}
handleViewportChange() {
if (!this.active || this.destroyed) return;
+8 -9
View File
@@ -10,15 +10,14 @@
// fully hidden.
// Visible height of the sheet at each detent, as a fraction of the viewport.
// The expanded stop is the whole sheet, whose height is the viewport minus the
// small gap kept above it (see computeSheetHeight).
export const DETENT_FRACTIONS = {
expanded: 0.92,
expanded: 1,
medium: 0.55,
collapsed: 0.3,
};
// The sheet never grows beyond this fraction of the viewport.
export const MAX_SHEET_FRACTION = 0.92;
// Fling speed (px/ms) at or above which a release moves one detent in the
// direction of the gesture instead of snapping to the nearest detent.
export const FLING_THRESHOLD = 0.5;
@@ -31,11 +30,11 @@ export function clamp(value, min, max) {
return Math.min(Math.max(value, min), max);
}
export function computeSheetHeight(
viewportHeight,
maxFraction = MAX_SHEET_FRACTION
) {
return Math.round(viewportHeight * maxFraction);
// The sheet fills the viewport down from `topGap` pixels, so a fully expanded
// sheet reaches up to the top of the search field while leaving that strip
// visible above it.
export function computeSheetHeight(viewportHeight, topGap = 0) {
return Math.max(0, Math.round(viewportHeight - topGap));
}
// Build the list of reachable detents for a given viewport and sheet height.
+8 -8
View File
@@ -8,10 +8,7 @@ import {
waitUntil,
} from '@ember/test-helpers';
import { setupApplicationTest } from 'marco/tests/helpers';
import {
computeDetentLayout,
computeSheetHeight,
} from 'marco/utils/sheet-detents';
import { computeDetentLayout } from 'marco/utils/sheet-detents';
import Service from '@ember/service';
import sinon from 'sinon';
@@ -395,16 +392,19 @@ module('Acceptance | bottom sheet', function (hooks) {
.exists('the parent shows the search results');
// Place details opens at medium, and the background is pinned to the
// minimum so it can never peek above the top sheet.
const sheetHeight = computeSheetHeight(window.innerHeight);
// minimum so it can never peek above the top sheet. Read the sheet height
// the modifier wrote rather than recomputing the geometry.
const top = document.querySelector('.sheet-top');
const background = document.querySelector('.sheet-background');
const sheetHeight = parseFloat(
top.style.getPropertyValue('--sheet-height')
);
const layout = computeDetentLayout({
viewportHeight: window.innerHeight,
sheetHeight,
});
const mediumOffset = layout.find((d) => d.name === 'medium')?.offset;
const minimumOffset = layout[layout.length - 1].offset;
const top = document.querySelector('.sheet-top');
const background = document.querySelector('.sheet-background');
await waitUntil(
() =>
parseFloat(top.style.getPropertyValue('--sheet-offset')) ===
+10 -9
View File
@@ -8,18 +8,19 @@ import {
} from 'marco/utils/sheet-detents';
const VIEWPORT = 800;
// 0.92 * 800
const SHEET = computeSheetHeight(VIEWPORT); // 736
// expanded: 736 - 736 = 0, medium: 736 - 440 = 296, collapsed: 736 - 240 = 496
// No top gap, so the sheet fills the viewport.
const SHEET = computeSheetHeight(VIEWPORT); // 800
// expanded: 800 - 800 = 0, medium: 800 - 440 = 360, collapsed: 800 - 240 = 560
const LAYOUT = computeDetentLayout({
viewportHeight: VIEWPORT,
sheetHeight: SHEET,
});
module('Unit | Utility | sheet-detents', function () {
test('computeSheetHeight caps the sheet to a fraction of the viewport', function (assert) {
assert.strictEqual(computeSheetHeight(800), 736);
assert.strictEqual(computeSheetHeight(1000, 0.5), 500);
test('computeSheetHeight fills the viewport minus the top gap', function (assert) {
assert.strictEqual(computeSheetHeight(800), 800);
assert.strictEqual(computeSheetHeight(800, 8), 792);
assert.strictEqual(computeSheetHeight(100, 200), 0, 'never negative');
});
test('computeDetentLayout produces ascending offsets with expanded first', function (assert) {
@@ -29,8 +30,8 @@ module('Unit | Utility | sheet-detents', function () {
'detents are ordered by ascending offset'
);
assert.strictEqual(findDetent(LAYOUT, 'expanded').offset, 0);
assert.strictEqual(findDetent(LAYOUT, 'medium').offset, 296);
assert.strictEqual(findDetent(LAYOUT, 'collapsed').offset, 496);
assert.strictEqual(findDetent(LAYOUT, 'medium').offset, 360);
assert.strictEqual(findDetent(LAYOUT, 'collapsed').offset, 560);
});
test('computeDetentLayout keeps a single clamped detent for short sheets', function (assert) {
@@ -120,7 +121,7 @@ module('Unit | Utility | sheet-detents', function () {
);
assert.strictEqual(
resolveSnap({
offset: 500,
offset: 570,
velocity: 0.6,
layout: LAYOUT,
sheetHeight: SHEET,