Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/table-filter-trigger-iconbutton.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[fix] Table: the column filter trigger in a header cell is now Core's ghost `IconButton` at size `sm`, so it takes Button's own hover, focus, press and touch target instead of a hand-styled button. Its name, popover and accent color when a filter is set are unchanged.
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved

@cixzhang
46 changes: 46 additions & 0 deletions apps/storybook/stories/TableFiltering.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,49 @@ export const EmptyState: Story = {
);
},
};

/**
* Sortable and filterable header cells at each density, so the header's
* controls can be compared side by side.
*/
export const HeaderDensities: Story = {
render: () => {
const {config, applyFilters} = usePowerSearchConfig(fieldDefs);
const {filters, onFilterChange} = useTableFilterState();
const {sortConfig, applySort} = useTableSortableState<Employee>({
data: employees,
});
const columns: TableColumn<Employee>[] = [
{key: 'name', header: 'Name', sortable: true, filter: 'name'},
{key: 'role', header: 'Role', sortable: true, filter: 'role'},
{key: 'level', header: 'Level', sortable: true},
{key: 'department', header: 'Department'},
];
const filterPlugin = useTableFiltering<Employee>({
filters,
onFilterChange,
searchConfig: config,
});
const sortPlugin = useTableSortable<Employee>(sortConfig);
const data = applySort(
applyFilters(
toSearchFilters(filters, columns, config) as PowerSearchFilter[],
employees,
),
).slice(0, 2);
return (
<div style={{maxWidth: 640, display: 'grid', gap: 16}}>
{(['compact', 'balanced', 'spacious'] as const).map(density => (
<Table
key={density}
data={data}
columns={columns}
idKey="name"
density={density}
plugins={{sort: sortPlugin, filter: filterPlugin}}
/>
))}
</div>
);
},
};
8 changes: 8 additions & 0 deletions docs/specs/components/Table/TableHeaderCell.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ Consumer syntax and examples belong in `TableHeaderCell.doc.mjs`.

Consumer migration instructions belong in consumer docs and release notes.

## Current-state impact

- **Touch band clipped at compact density.** A header control such as the
column filter trigger or the Sort control is a 28 px Button with a 44 px touch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this pull request the Sort control is still the native <button> around the label (useTableSortable.tsx:373), not a Button; it becomes one in #14105. Drop "or the Sort control" here. Measured locally, the compact band reaches about 4 px above and 3.5 px below the 28 px button (a tap 1 to 3 px away still reaches it), so "a tap more than about 4 px above or below the button misses it" is more exact.

band (`spec:AST-094` FR42), but the cell's `overflow: hidden` clips the band
to the cell. At compact density the header row is 36.5 px, so a tap just
above or below the button misses it.

## Ownership boundary

**Owns**
Expand Down
46 changes: 9 additions & 37 deletions packages/core/src/Table/plugins/filtering/useTableFiltering.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import {
type ReactNode,
} from 'react';
import * as stylex from '@stylexjs/stylex';
import {spacingVars, radiusVars} from '../../../theme/tokens.stylex';
import {spacingVars} from '../../../theme/tokens.stylex';
import {Icon} from '../../../Icon';
import {Button} from '../../../Button';
import {IconButton} from '../../../IconButton/IconButton';
import {Popover} from '../../../Popover';
import {TextInput} from '../../../TextInput';
import {NumberInput} from '../../../NumberInput';
Expand Down Expand Up @@ -381,36 +382,13 @@ const filterStyles = stylex.create({
marginTop: spacingVars['--spacing-1'],
minWidth: 0,
},
triggerButton: {
backgroundColor: 'transparent',
borderWidth: 0,
borderStyle: 'none',
cursor: {
default: 'pointer',
':is(:disabled,[aria-disabled="true"])': 'default',
},
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
padding: 0,
borderRadius: radiusVars['--radius-element'],
flexShrink: 0,
// Minimum 44px touch target on coarse pointer devices (iOS guideline).
'@media (pointer: coarse)': {
minWidth: '44px',
minHeight: '44px',
},
},
triggerInactive: {
opacity: {
default: 0.35,
':is(th:hover *)': 1,
':focus-visible': 1,
},
},
triggerActive: {
opacity: 1,
},
popoverContent: {
width: '240px',
},
Expand Down Expand Up @@ -1027,20 +1005,14 @@ function PopoverFilterTrigger({
</div>
</FilterStoreContext>
}>
<button
type="button"
aria-label={t('@astryx.tableFiltering.filterByColumn', {header})}
<IconButton
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
label={t('@astryx.tableFiltering.filterByColumn', {header})}
aria-haspopup="dialog"
{...stylex.props(
filterStyles.triggerButton,
hasValue ? filterStyles.triggerActive : filterStyles.triggerInactive,
)}>
<Icon
icon="funnel"
size="xsm"
color={hasValue ? 'accent' : 'secondary'}
/>
</button>
variant="ghost"
size="sm"
icon={<Icon icon="funnel" color={hasValue ? 'accent' : 'secondary'} />}
xstyle={hasValue ? undefined : filterStyles.triggerInactive}
/>
</Popover>
);
}
Expand Down
Loading