Skip to content

Commit

Permalink
make Table cells responsive on narrow widths (#1863)
Browse files Browse the repository at this point in the history
- All columns have an overridable non-zero min-width defined to prevent them from getting too small.
- Cells will use shadow DOM to clamp automatically if the value is a string (can be explicitly enabled/disabled).
- Filter/sort icons will wrap into next line on narrow widths.
- Filter icon is now always visible (previously only on hover).
- Sort icon occupies less space.
  • Loading branch information
mayank99 authored Mar 19, 2024
1 parent 210e83a commit 65ac2b6
Show file tree
Hide file tree
Showing 61 changed files with 385 additions and 802 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-lamps-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@itwin/itwinui-css": minor
---

The filter button inside a Table will now always be visible, instead of only being shown on hover/focus.
5 changes: 5 additions & 0 deletions .changeset/six-pans-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@itwin/itwinui-react": minor
---

The filter button inside a Table will now always be visible, instead of only being shown on hover/focus.
8 changes: 8 additions & 0 deletions .changeset/tender-seas-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@itwin/itwinui-react": minor
---

The responsive behavior of Table columns has been improved in a few different ways:
- All columns now have a non-zero default min-width. While we still recommend passing a custom min-width based on your data, this default will help prevent resizable columns from becoming too small.
- The filter and sort icons in a column header will now wrap to the next line, before the text starts wrapping.
- For cells that have a string value, the value will be automatically truncated after three lines.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 6 additions & 21 deletions packages/itwinui-css/src/table/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@
cursor: grabbing;
}

.iui-table-filter-button:not([data-iui-active='true']) {
opacity: 0;
}

> .iui-table-resizer {
block-size: 100%;
inline-size: var(--iui-size-m);
Expand Down Expand Up @@ -93,23 +89,14 @@
opacity: 1;
}

&:is(:hover, :focus-visible, :has(:focus-visible)) {
&:is(:hover, :focus-visible),
&:has(:focus-visible) {
background-color: var(--iui-color-background-hover);

:is(.iui-table-sort, .iui-table-filter-button) {
.iui-table-sort {
opacity: 1;
}
}

@supports not selector(:has(+ *)) {
&:focus-within {
background-color: var(--iui-color-background-hover);

:is(.iui-table-sort, .iui-table-filter-button) {
opacity: 1;
}
}
}
}

.iui-table-reorder-bar {
Expand Down Expand Up @@ -336,14 +323,12 @@
flex-grow: 1;
align-items: center;
flex-wrap: wrap;
justify-content: flex-end;
margin-inline-end: var(--iui-size-s);

.iui-table-cell-end-icon {
// Hardcoded size of the borderless button so that the icons are centered
inline-size: 28px;
block-size: 28px;
margin-inline-end: initial;
inline-size: unset;
block-size: unset;
margin: 0;
margin-inline-start: auto;
}
}
Expand Down
20 changes: 20 additions & 0 deletions packages/itwinui-react/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ vi.mock('./src/core/utils/hooks/useGlobals.js', () => {
};
});

vi.mock('@testing-library/react', async () => {
const originalRtl = await vi.importActual<
typeof import('@testing-library/react')
>('@testing-library/react');

return {
...originalRtl,
/**
* Wrapper over `@testing-library/react`'s `render()` that also waits for all
* microtasks to be flushed. This is necessary for ShadowRoot to be tested properly.
*/
render: (...args: Parameters<typeof originalRtl.render>) => {
vi.useFakeTimers({ toFake: ['queueMicrotask'] });
const result = originalRtl.render(...args);
originalRtl.act(() => vi.runAllTicks());
return result;
},
};
});

afterEach(() => {
vi.useRealTimers();
});
4 changes: 3 additions & 1 deletion packages/itwinui-react/src/core/Table/SubRowExpander.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ export type SubRowExpanderProps<T extends Record<string, unknown>> = {
isDisabled: boolean;
cellProps: CellProps<T>;
density?: 'default' | 'condensed' | 'extra-condensed';
[k: string]: unknown;
};

export const SubRowExpander = <T extends Record<string, unknown>>(
props: SubRowExpanderProps<T>,
) => {
const { cell, isDisabled, cellProps, expanderCell, density } = props;
const { cell, isDisabled, cellProps, expanderCell, density, ...rest } = props;

return (
<>
Expand All @@ -40,6 +41,7 @@ export const SubRowExpander = <T extends Record<string, unknown>>(
cell.row.toggleRowExpanded();
}}
disabled={isDisabled}
{...rest}
>
{
<SvgChevronRight
Expand Down
Loading

0 comments on commit 65ac2b6

Please sign in to comment.