Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

PowerSearch: fit the filter editor on narrow screens (#4768)

AK56fa70d7ad0f
diff --git a/.changeset/powersearch-narrow-viewport-fit.md b/.changeset/powersearch-narrow-viewport-fit.md
new file mode 100644
index 0000000000..6c4d330b79
--- /dev/null
+++ b/.changeset/powersearch-narrow-viewport-fit.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] PowerSearch: the edit popover now fits narrow viewports — its 400px minimum width yields to the screen width, and the filter row wraps instead of overflowing when long translated operator labels don't fit. An editor anchored near the screen edge now stays on its own side at the width available there, wrapping internally, instead of flipping across the anchor to keep 400px.
+
+@AKnassa
diff --git a/packages/core/src/PowerSearch/PowerSearch.tsx b/packages/core/src/PowerSearch/PowerSearch.tsx
index b7b752165d..463c1d6f08 100644
--- a/packages/core/src/PowerSearch/PowerSearch.tsx
+++ b/packages/core/src/PowerSearch/PowerSearch.tsx
@@ -109,7 +109,12 @@ const tokenValueStyles = stylex.create({
const popoverLayerStyles = stylex.create({
layer: {
width: 'anchor-size(width)',
- minWidth: 400,
+ // Floor for comfortable editing, yielding when the available inline
+ // space cannot fit it, so the editor stays on-screen at narrow viewport
+ // widths (#4761). Percentages resolve against the position-area region
+ // (anchor start edge to viewport end), falling back to the viewport
+ // where area sizing is not honored.
+ minWidth: `min(400px, calc(100% - ${spacingVars['--spacing-4']}))`,
},
});
diff --git a/packages/core/src/PowerSearch/PowerSearchEditPopover.test.tsx b/packages/core/src/PowerSearch/PowerSearchEditPopover.test.tsx
index 072b48fe81..9390fe46c8 100644
--- a/packages/core/src/PowerSearch/PowerSearchEditPopover.test.tsx
+++ b/packages/core/src/PowerSearch/PowerSearchEditPopover.test.tsx
@@ -12,6 +12,8 @@ import {
} from 'vitest';
import {render, screen, fireEvent, act} from '@testing-library/react';
import React, {useState} from 'react';
+import * as stylex from '@stylexjs/stylex';
+import {spacingVars} from '../theme/tokens.stylex';
import {PowerSearch} from './PowerSearch';
import {PowerSearchEditPopover} from './PowerSearchEditPopover';
import {useInternalConfig} from './useInternalConfig';
@@ -326,3 +328,202 @@ describe('PowerSearch', () => {
expect(onSave).toHaveBeenCalledTimes(1);
});
});
+
+// =============================================================================
+// Narrow-width layout (#4761)
+// =============================================================================
+
+// jsdom performs no real layout (and never matches @container conditions), so
+// these tests assert the declarations that produce the narrow-width behavior
+// rather than measured geometry, via StyleX probe classes: one deterministic
+// atomic class per property/value/condition, so an element carries a probe's
+// classes exactly when it has the same declaration. The dev debug class
+// (contains "__") is excluded.
+const CHIP_ROW_COLLAPSE = '@container (max-width: 399px)';
+
+const probe = stylex.create({
+ responsiveLayerMinWidth: {
+ minWidth: `min(400px, calc(100% - ${spacingVars['--spacing-4']}))`,
+ },
+ fixedLayerMinWidth: {minWidth: 400},
+ queryContainer: {containerType: 'inline-size'},
+ responsiveWrap: {
+ flexWrap: {default: 'nowrap', [CHIP_ROW_COLLAPSE]: 'wrap'},
+ },
+ cellMaxWidth: {maxWidth: '100%'},
+ nestedFieldCellWidth: {width: 200},
+});
+
+function atomicClasses(style: (typeof probe)[keyof typeof probe]): string[] {
+ const {className = ''} = stylex.props(style);
+ const classes = className
+ .split(' ')
+ .filter(c => c !== '' && !c.includes('__'));
+ // A probe resolving to no atomic classes would make every assertion built
+ // on it vacuous, including the not-toHaveClass loops; fail loudly instead.
+ expect(classes.length).toBeGreaterThan(0);
+ return classes;
+}
+
+function expectProbeClasses(
+ el: HTMLElement,
+ style: (typeof probe)[keyof typeof probe],
+) {
+ for (const cls of atomicClasses(style)) {
+ expect(el).toHaveClass(cls);
+ }
+}
+
+describe('narrow-width layout (#4761)', () => {
+ function EditHarness() {
+ const internalConfig = useInternalConfig(testConfig);
+ return (
+ <PowerSearchEditPopover
+ config={internalConfig}
+ filter={{
+ field: 'status',
+ operator: 'is',
+ value: {type: 'string', value: 'open'},
+ }}
+ mode="edit"
+ onSave={() => {}}
+ onCancel={() => {}}
+ />
+ );
+ }
+
+ function getChipRow(container: HTMLElement): HTMLElement {
+ // Locate the chip row by its collapse declaration, then sanity-check it
+ // really is the row holding the field / operator / value cells.
+ const [rowCls] = atomicClasses(probe.responsiveWrap);
+ const row = container.querySelector(`.${rowCls}`) as HTMLElement;
+ expect(row).not.toBeNull();
+ expect(row).toHaveClass('astryx-stack');
+ expect(row.children).toHaveLength(3);
+ return row;
+ }
+
+ it('popover root establishes the container the collapse query measures', () => {
+ const {container} = render(<EditHarness />);
+
+ // Without inline-size containment on the root, no @container condition
+ // in this file can match and the chip rows would never wrap.
+ const root = container.firstElementChild as HTMLElement;
+ expect(root).not.toBeNull();
+ expectProbeClasses(root, probe.queryContainer);
+ });
+
+ it('filter chip row wraps below the collapse width instead of overflowing', () => {
+ const {container} = render(<EditHarness />);
+
+ const row = getChipRow(container);
+ expectProbeClasses(row, probe.responsiveWrap);
+ });
+
+ it('operator cell is capped at the row width', () => {
+ const {container} = render(<EditHarness />);
+
+ // Capped so a long translated operator label truncates inside the
+ // Selector trigger instead of pushing the row wider than the popover.
+ const operatorCell = getChipRow(container).children[1] as HTMLElement;
+ expectProbeClasses(operatorCell, probe.cellMaxWidth);
+ });
+
+ it('nested sub-filter rows wrap instead of overflowing on one line', () => {
+ const nestedConfig: PowerSearchConfig = {
+ name: 'test-nested',
+ fields: [
+ {
+ key: 'group',
+ label: 'Group',
+ operators: [
+ {key: 'all_of', label: 'all of', value: {type: 'nested'}},
+ ],
+ },
+ {
+ key: 'status',
+ label: 'Status',
+ operators: [{key: 'is', label: 'is', value: {type: 'string'}}],
+ },
+ ],
+ };
+
+ function NestedHarness() {
+ const internalConfig = useInternalConfig(nestedConfig);
+ return (
+ <PowerSearchEditPopover
+ config={internalConfig}
+ filter={{
+ field: 'group',
+ operator: 'all_of',
+ value: {
+ type: 'nested',
+ value: [
+ {
+ field: 'status',
+ operator: 'is',
+ value: {type: 'string', value: 'open'},
+ },
+ ],
+ },
+ }}
+ mode="edit"
+ onSave={() => {}}
+ onCancel={() => {}}
+ />
+ );
+ }
+
+ const {container} = render(<NestedHarness />);
+
+ // Locate the sub-filter row through its fixed-width field cell.
+ const [cellCls] = atomicClasses(probe.nestedFieldCellWidth);
+ const fieldCell = container.querySelector(`.${cellCls}`) as HTMLElement;
+ expect(fieldCell).not.toBeNull();
+ const row = fieldCell.parentElement as HTMLElement;
+ expect(row).toHaveClass('astryx-stack');
+ expectProbeClasses(row, probe.responsiveWrap);
+
+ // The fixed-width cells are capped so they cannot clip in containers
+ // narrower than their design width (or under deep TreeList indentation).
+ expectProbeClasses(fieldCell, probe.cellMaxWidth);
+ const operatorCell = row.children[1] as HTMLElement;
+ expectProbeClasses(operatorCell, probe.cellMaxWidth);
+ });
+
+ it('edit popover layer yields to viewports narrower than its 400px floor', () => {
+ const filters: PowerSearchFilter[] = [
+ {field: 'status', operator: 'is', value: {type: 'string', value: 'open'}},
+ ];
+
+ function Harness() {
+ const [currentFilters, setCurrentFilters] = useState(filters);
+ return (
+ <PowerSearch
+ config={testConfig}
+ filters={currentFilters}
+ onChange={newFilters => setCurrentFilters([...newFilters])}
+ />
+ );
+ }
+
+ render(<Harness />);
+
+ act(() => {
+ fireEvent.click(screen.getByText('Status: is'));
+ flushRAF();
+ });
+
+ const layer = screen
+ .getByText('Cancel')
+ .closest('[popover]') as HTMLElement;
+ expect(layer).not.toBeNull();
+
+ // The fixed 400px floor is replaced by one clamped to the available
+ // inline space, so the popover never opens wider than the screen.
+ expectProbeClasses(layer, probe.responsiveLayerMinWidth);
+ for (const cls of atomicClasses(probe.fixedLayerMinWidth)) {
+ expect(layer).not.toHaveClass(cls);
+ }
+ });
+});
diff --git a/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx b/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx
index ce0fe0e679..c70eb490ff 100644
--- a/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx
+++ b/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx
@@ -32,13 +32,23 @@ import type {
OperatorValue,
} from './types';
+// Below the popover layer's 400px floor (see popoverLayerStyles in
+// PowerSearch.tsx) the chip rows collapse from one line to wrapped lines.
+// A container query, not a viewport one, so the rows track the width the
+// popover actually got (#4761).
+const CHIP_ROW_COLLAPSE = '@container (max-width: 399px)';
+
const styles = stylex.create({
container: {
overflow: 'hidden',
+ containerType: 'inline-size',
},
content: {
padding: spacingVars['--spacing-4'],
},
+ chipRow: {
+ flexWrap: {default: 'nowrap', [CHIP_ROW_COLLAPSE]: 'wrap'},
+ },
footer: {
padding: spacingVars['--spacing-3'],
paddingTop: 0,
@@ -51,6 +61,9 @@ const styles = stylex.create({
operatorSelector: {
flexGrow: 1,
flexShrink: 0,
+ // Long translated operator labels truncate in the Selector trigger
+ // instead of pushing the row wider than the popover (#4761).
+ maxWidth: '100%',
},
valueEditor: {
flexGrow: 2,
@@ -63,10 +76,12 @@ const styles = stylex.create({
nestedFieldSelector: {
flexShrink: 0,
width: 200,
+ maxWidth: '100%',
},
nestedOperatorSelector: {
flexShrink: 0,
width: 180,
+ maxWidth: '100%',
},
nestedRow: {
width: '100%',
@@ -309,7 +324,7 @@ function NestedSubFilterRow({
);
return (
- <HStack gap={2} vAlign="center">
+ <HStack gap={2} vAlign="center" xstyle={styles.chipRow}>
<div {...stylex.props(styles.nestedFieldSelector)}>
<Selector
label={t('@astryx.powersearch.editor.field')}
@@ -802,7 +817,7 @@ export function PowerSearchEditPopover({
return (
<div {...stylex.props(styles.container)} onKeyDown={handleKeyDown}>
<div {...stylex.props(styles.content)}>
- <HStack gap={2}>
+ <HStack gap={2} xstyle={styles.chipRow}>
<div {...stylex.props(styles.fieldSelector)}>
<Selector
label={t('@astryx.powersearch.editor.field')}