-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nimble Table: cell view (custom element) and cell state changes (#1138)
# Pull Request ## 🤨 Rationale Fixes #997 ## 👩💻 Implementation Implementation is similar to what was outlined in the the [HLD](https://github.com/ni/nimble/blob/main/packages/nimble-components/src/table/specs/cell-state-when-scrolling-hld.md) ([PR](#1052)): - Add a `TableCellView<TCellRecord, TColumnConfig>` class. TableCellView instances will be used in `TableCell`s, instead of the old approach (column-provided cellTemplate and cellStyles). - Add `cellViewTag` property to `TableColumn` (links the column with the associated `TableCellView` type) - `TableCellView` defines a `focusedRecycleCallback()` method which is a no-op by default. If a cell view contains a focusable element, and a cell is focused, and then a scroll (row recycle) occurs, this gives the cell view an opportunity to commit/blur/etc. - We don't yet have a column type exercising this, but there's a new autotest for this code path. - If a cell action menu is open when a scroll/ row recycle occurs, the action menu is closed (via the associated menu button). ## 🧪 Testing - Updated existing autotests - Added new tests for `focusedRecycleCallback` and the code that closes action menus on scroll - Manually tested table in Storybook + Angular + Blazor example apps ## ✅ Checklist - [x] I have updated the project documentation to reflect my changes or determined no changes are needed.
- Loading branch information
Showing
24 changed files
with
367 additions
and
244 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-components-0d465c53-f139-410c-b252-e3da15e453e2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Table updates: use custom element (TableCellView) in cells, cells are notified of row recycling, action menus are closed on scroll/ row recycles.", | ||
"packageName": "@ni/nimble-components", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/nimble-components/src/table-column/base/cell-view/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { observable } from '@microsoft/fast-element'; | ||
import { FoundationElement } from '@microsoft/fast-foundation'; | ||
import type { TableCellRecord, TableCellState } from '../types'; | ||
|
||
/** | ||
* Base class for table cell views, which are used within the nimble-table-cell. | ||
* Each TableColumn type has a corresponding TableCellView type (linked via TableColumn.cellViewTag). | ||
*/ | ||
export abstract class TableCellView< | ||
TCellRecord extends TableCellRecord = TableCellRecord, | ||
TColumnConfig = unknown | ||
> | ||
extends FoundationElement | ||
implements TableCellState<TCellRecord, TColumnConfig> { | ||
@observable | ||
public cellRecord!: TCellRecord; | ||
|
||
@observable | ||
public columnConfig!: TColumnConfig; | ||
|
||
/** | ||
* Called if an element inside this cell view has focus, and this row/cell is being recycled. | ||
* Expected implementation is to commit changes as needed, and blur the focusable element (or close | ||
* the menu/popup/etc). | ||
*/ | ||
public focusedRecycleCallback(): void {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 11 additions & 9 deletions
20
packages/nimble-components/src/table-column/base/tests/table-column.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 11 additions & 9 deletions
20
packages/nimble-components/src/table-column/mixins/tests/fractional-width-column.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/nimble-components/src/table-column/text/cell-view/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { observable, volatile } from '@microsoft/fast-element'; | ||
import { DesignSystem } from '@microsoft/fast-foundation'; | ||
import type { | ||
TableColumnTextCellRecord, | ||
TableColumnTextColumnConfig | ||
} from '..'; | ||
import { TableCellView } from '../../base/cell-view'; | ||
import { styles } from './styles'; | ||
import { template } from './template'; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'nimble-table-column-text-cell-view': TableColumnTextCellView; | ||
} | ||
} | ||
|
||
/** | ||
* A cell view for displaying strings | ||
*/ | ||
export class TableColumnTextCellView extends TableCellView< | ||
TableColumnTextCellRecord, | ||
TableColumnTextColumnConfig | ||
> { | ||
/** @internal */ | ||
@observable | ||
public isValidContentAndHasOverflow = false; | ||
|
||
/** @internal */ | ||
public textSpan!: HTMLElement; | ||
|
||
@volatile | ||
public get content(): string { | ||
return typeof this.cellRecord.value === 'string' | ||
? this.cellRecord.value | ||
: this.columnConfig.placeholder; | ||
} | ||
} | ||
|
||
const textCellView = TableColumnTextCellView.compose({ | ||
baseName: 'table-column-text-cell-view', | ||
template, | ||
styles | ||
}); | ||
DesignSystem.getOrCreate().withPrefix('nimble').register(textCellView()); | ||
export const tableColumnTextCellViewTag = DesignSystem.tagFor( | ||
TableColumnTextCellView | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/nimble-components/src/table-column/text/cell-view/template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { html, ref } from '@microsoft/fast-element'; | ||
|
||
import type { TableColumnTextCellView } from '.'; | ||
|
||
export const template = html<TableColumnTextCellView>` | ||
<span | ||
${ref('textSpan')} | ||
class="${x => (typeof x.cellRecord.value === 'string' ? '' : 'placeholder')}" | ||
@mouseover="${x => { | ||
x.isValidContentAndHasOverflow = !!x.content && x.textSpan.offsetWidth < x.textSpan.scrollWidth; | ||
}}" | ||
@mouseout="${x => { | ||
x.isValidContentAndHasOverflow = false; | ||
}}" | ||
title=${x => (x.isValidContentAndHasOverflow ? x.content : null)} | ||
> | ||
${x => x.content} | ||
</span> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
packages/nimble-components/src/table-column/text/template.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.