-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[Table] Newly focused cell after keyboard navigation is now transformed #2988
Conversation
Thanks for your interest in palantir/blueprint, @ntamas! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ntamas can you please set the GH_AUTH_TOKEN
env variable for preview comments?
https://github.com/palantir/blueprint/blob/develop/CONTRIBUTING.md#enable-preview-comments
packages/table/src/table.tsx
Outdated
@@ -1826,6 +1826,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) { | |||
// tslint:disable-next-line no-unnecessary-callback-wrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have to disable this? if so, leave another //comment explaining why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct -- there is no need to disable this. Shall I add another commit to this PR to remove this line and will you squash it if it gets merged eventually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes add commits. do not force push on PRs.
packages/table/src/table.tsx
Outdated
const { selectedRegionTransform } = this.props; | ||
if (selectedRegionTransform != null) { | ||
// tslint:disable-next-line no-unnecessary-callback-wrapper | ||
newSelectionRegions.forEach(region => selectedRegionTransform(region, undefined)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the explicit undefined
? i'm not familiar with this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selectedRegionTransform()
is a function that takes a region and a mouse event that triggered the selection. In this case, there is no mouse event so the best I could do is to pass undefined
as the second argument. (I did not want to mess around with the typing of selectedRegionTransform
as that would be an API breakage). Actually, I was surprised to see that TypeScript accepts undefined
for an argument that is typed as a MouseEvent
.
Also, strangely enough, TypeScript complains if I omit the second argument ("Expected 2-3 arguments, got 1"), so that's why we need an explicit undefined
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is not valid. it only accepts undefined
because we have not enabled
strictNullChecks
compiler options.
I have added the auth token after I have realized that CircleCI failed the checks and I have re-ran the pipeline on CircleCI. Is there anything else I need to do? |
packages/table/src/table.tsx
Outdated
this.handleSelection(newSelectionRegions); | ||
const transformedSelectionRegions = | ||
selectedRegionTransform != null | ||
? newSelectionRegions.map(region => selectedRegionTransform(region, undefined)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@@ -1829,7 +1829,7 @@ export class Table extends AbstractComponent<ITableProps, ITableState> { | |||
const { selectedRegionTransform } = this.props; | |||
const transformedSelectionRegions = | |||
selectedRegionTransform != null | |||
? newSelectionRegions.map(region => selectedRegionTransform(region, undefined)) | |||
? newSelectionRegions.map(region => selectedRegionTransform(region, e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have ICoordinateData
for the third argument? perhaps newFocusedCell
? (i'm not looking at the code actively)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ICoordinateData
is defined in src/interactions/draggable.tsx
and it seems to hold data that is relevant only for dragging gestures. The only time when this argument is used at the moment is in handleDragMove()
in src/interactions/selectable.tsx
. I would say that it is not relevant here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! thanks @ntamas
Fixes #2871
Changes proposed in this pull request:
This pull request implements a change to the
Table
component that passes the newly focused cell through theselectedRegionTransform
function of the table if it is present. This is to ensure that invariants enforced in theselectedRegionTransform
function (e.g., "only whole rows should be selected") are not violated after the user navigates to another cell with the keyboard.Reviewers should focus on:
Please check my changes made to the
handleFocusMove()
method of theTable
component. I have updated the table dev app as well to make this change easier to test.