-
Notifications
You must be signed in to change notification settings - Fork 842
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
Datagrid remaining keyboard shortcuts #2519
Datagrid remaining keyboard shortcuts #2519
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
setFocusedCell([0, y]); | ||
break; | ||
default: | ||
if ( |
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.
@chandlerprall Should we move the whole switch statement to an if
/else
? Having to do this feels silly...
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 took the liberty to go ahead and make the change as suggested by @myasonik . Feel free to let me know if you want the switch statement back.
@ffknob could you also add tests for each of the new keyboard shortcuts added? |
Just did... Good opportunity to learn a little bit about testing framework. |
I tried taking a look at why My best guess is that changing the page changes what setting |
I'm having a hard time trying to simply resolve the merge conflict in the
What did I do wrong? |
Never mind... It turns out I had to |
I don't think Perhaps something is missing in this hook in order to fire the callback up? I tried adding (I have almost no experience with React, but I'll try to investigate further... we are almost there to get this mergeable) |
Thanks for putting all of this together! I haven't reviewed all of the changes, only looked so far at handling of page up & page down, and have a couple changes:
refactored: } else if (keyCode === keyCodes.PAGE_DOWN) {
if (props.pagination) {
event.preventDefault();
const totalRowCount = props.rowCount;
const pageIndex = props.pagination.pageIndex;
const pageSize = props.pagination.pageSize;
const pageCount = Math.ceil(totalRowCount / pageSize);
if (pageIndex < pageCount) {
props.pagination.onChangePage(props.pagination.pageIndex + 1);
setFocusedCell([focusedCell[0], 0]);
}
}
} else if (keyCode === keyCodes.PAGE_UP) {
if (props.pagination) {
event.preventDefault();
const pageIndex = props.pagination.pageIndex;
if (pageIndex > 0) {
props.pagination.onChangePage(props.pagination.pageIndex - 1);
setFocusedCell([focusedCell[0], 0]);
}
}
} I don't yet have a solution for re-focusing the target cell after pagination. The code below correctly sets the value (you can page down & tab & shift+tab and the correct cell is focused). The problem is on pagination all the cells unmount and are recreated, and there is no existing lifecycle point for a cell to focus itself on mount, especially since it needs to know if focus was previously owned on the table. Thoughts include:
I'm leaning toward the last option as it relies on a pure (thin) abstraction instead of sharing/leaking DOM elements. |
Yes, instinctively I think this is the best way (when I was testing I kept trying to go forward by pressing Page Down), but I only swap those on purpouse because I thought that the reasoning should be "Page Up" for incresing page numbers and "Page Down" for decresing them... Bu as I said, as a future user of this feature I totally agree with you, they were swapped
Ok
I understand that, but this way I couldn't get the tests to pass anymore... It looked a lot like the problem was with the paging (LEFT/RIGHT/HOME/END worked, but the PG UP/PG DOWN had no effect, the cell text value received was always like no page movement had happened)
Nice, but I changed a little bit to focus not only on the same column, but also in the same row. Let me know if you think that's not the best approach and I revert to same column/top row.
Thanks for that!
This goes way beyond my React knowledge (I work with Angular). If you could point me an article I'd gladly try to solve this for finally finishing this PR. Did you mean the Thanks for the code review! |
I thought this was stated in the spec, but I just checked and there isn't a mention either way. @myasonik do you have any thoughts here?
I think the steps here are:
That should set up the overall communication. There's probably something I left out, or a small edge case lurking in the details - feel free to ask for any clarification, etc! We've been wanting to move some other props into a context, so this is a big step toward supporting that in addition to solving the page up/down focus. |
For page up and page down, I think staying on the same row and column position is appropriate 👍 (I wanted to restate the whole sentence to make sure we're on the same page. So if I misunderstood please let me know!) |
pagination focus problem
Hi @chandlerprall
So I am currently stucked in perhaps some Javascript context/scope issue. I have to stop for today but next time I'll try to figure this out and also take a look at the test case @myasonik mentioned. Sorry if I misunderstood something from the steps you described. |
Some progress... The problem I have now, and I think this will be the last one before we can definetly see if this will work or not, is to where to call Here is the order in which things are happening currently:
I know that the point where I am currently calling |
Nice! That implementation is slick, and I especially like the nested arrays on The calls to |
It worked! Nice tip The only thing is that if the user is really fast (smashing the |
Thanks for all the effort on this, @ffknob ! I'm ready to do a full review pass on the changes, and will include a look at that not focused in the grid state (I definitely encountered it when testing the requestAnimationFrame solution). Knowing you are newer to React, I don't want to throw a bunch of suggestions/requests your way without reasons. Would you prefer:
|
at this point I think I prefer that you "PR against my branch". You'll definetly "Reactify" this implementation way faster than I could and I think I now have runned out of all little React that I knew... I'll definetly learn by your refactory and will appreciate any comments that will may leave in the PR. Thank you for all the support throughout this PR. It was really a very good opportunity to start to learn about the project, React, Jest and more. Will be waiting for your PR! |
05c7f10
to
0fd79d8
Compare
There was really only one issue, where the I didn't address the page up/down focus moving away from the grid during the page change, as it started ballooning into unrelated changes. I'll follow up with that in a future datagrid pass. |
Keyboard shortcut changes
jenkins test this |
Thanks for that @chandlerprall I think I managed to get your refactory merged into my branch and then updated this PR. (let me know if I did something wrong) |
Thanks! Everything looks good to me. I've asked @myasonik if he wants to take a final look and he should have time today for that. |
I just went through the PR and it works as expected (in that, your focus goes to the correct cell) in FF, Chrome, and Safari! I couldn't test IE11 though, Browserstack refused to load today for some reason... Could someone else check it? But that's pretty good results for something we expected to be a bug! This looks great, thank you for all your work @ffknob and thank you for the assist @chandlerprall! |
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.
Once someone can verify that nothing breaks in IE11, this is good to merge
@ffknob I hope you don't mind, I updated the PR description a touch (mostly touching the checklist) |
Not at all |
Glad to help! |
Tested the new shortcuts in IE11 & Edge, everything works as expected. |
Summary
(Related to #2482)
Implements some of the missing key shortcuts for the data grid: Home, End, Ctrl+Home, Ctrl+End, Page Down, Page Up
Checklist
- [ ] Checked in dark mode- [ ] Checked in mobile- [ ] Props have proper autodocs- [ ] Added documentation examples