Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Table] Newly focused cell after keyboard navigation is now transformed #2988

Merged
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions packages/table/src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1827,10 +1827,11 @@ export class Table extends AbstractComponent<ITableProps, ITableState> {
// change selection to match new focus cell location
const newSelectionRegions = [Regions.cell(newFocusedCell.row, newFocusedCell.col)];
const { selectedRegionTransform } = this.props;
if (selectedRegionTransform != null) {
newSelectionRegions.forEach(region => selectedRegionTransform(region, undefined));
}
this.handleSelection(newSelectionRegions);
const transformedSelectionRegions =
selectedRegionTransform != null
? newSelectionRegions.map(region => selectedRegionTransform(region, undefined))
Copy link
Contributor

Choose a reason for hiding this comment

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

this undefined breaks the type contract. blocker for this feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might be overkill but would it be acceptable to create a fake MouseEvent that simulates a click on the middle of the cell that the focus is being moved to?

Copy link
Contributor

Choose a reason for hiding this comment

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

this code is inside an event handler so we do have an event, it's just not a MouseEvent. best solution may be to change type to MouseEvent | FocusEvent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a KeyboardEvent there, not a FocusEvent, but I see your point. That would be a major version bump, though - so this has to wait until Blueprint 4, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh right my bad it is a keyboard event.

honestly this table library will never have a v4. we're working on a complete rewrite internally that will replace this implementation completely. it's going to be so much better but also quite different.

Copy link
Contributor

Choose a reason for hiding this comment

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

i'm willing to merge this change and declare it a bug fix, not an API break. makes sense for keyboard events to go through this flow just like mouse events. typescript users will see compile errors if they're relying on MouseEvent properties so at least it won't be silent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the typing of ISelectedRegionTransform in 6a35c0a - this version now also forwards the KeyboardEvent to the region transform function.

: newSelectionRegions;
this.handleSelection(transformedSelectionRegions);
this.handleFocus(newFocusedCell);

// keep the focused cell in view
Expand Down