-
-
Notifications
You must be signed in to change notification settings - Fork 72
fix keyboard navigation after copy/paste #90
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -5,9 +5,7 @@ import { colIsEditable } from 'dash-table/components/derivedState'; | |||
| import { | ||||
| KEY_CODES, | ||||
| isCtrlMetaKey, | ||||
| /*#if TEST_COPY_PASTE*/ | ||||
| isCtrlDown, | ||||
| /*#endif*/ | ||||
| isMetaKey, | ||||
| isNavKey | ||||
| } from 'dash-table/utils/unicode'; | ||||
|
|
@@ -137,20 +135,23 @@ export default class ControlledTable extends Component<ControlledTableProps> { | |||
| return; | ||||
| } | ||||
|
|
||||
| /*#if TEST_COPY_PASTE*/ | ||||
| const ctrlDown = isCtrlDown(e); | ||||
|
|
||||
| if (ctrlDown && e.keyCode === KEY_CODES.V) { | ||||
| /*#if TEST_COPY_PASTE*/ | ||||
| this.onPaste({} as any); | ||||
| e.preventDefault(); | ||||
| /*#endif*/ | ||||
| return; | ||||
| } | ||||
|
|
||||
| if (e.keyCode === KEY_CODES.C && ctrlDown && !is_focused) { | ||||
| /*#if TEST_COPY_PASTE*/ | ||||
| this.onCopy(e as any); | ||||
| e.preventDefault(); | ||||
| /*#endif*/ | ||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default handling of keys ends up changing the focus state, which affects how future keys are handled. 'Enter' is meant to set the focus "deeper" than the table, on the input itself, but not Ctrl+C / Ctrl+V. Exiting explicitly.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain what these
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The test build has a special build-time variable defined dash-table/webpack.test.config.js Line 3 in 5fd75e3
The loader reads through the files and keeps/removes the blocks based on whether the variable is defined or not. This is useful for defining build specific behavior or configurations that need to be more flexible than overriding an alias/file and/or not have to carry the conditional logic for tests/dev/etc. into production code. Created this loader a while ago when I encountered test cases I couldn't run on Selenium because it wasn't possible to open a file selector and choose a file..
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specifically, in this case, Cypress does not have good support of copy & paste events, so instead of letting the browser handle it, triggering the copy/paste processing manually when the key combinations are hit. This creates a gap between the test impl and the real impl but the alternative is to manual test features. |
||||
| return; | ||||
| } | ||||
| /*#endif*/ | ||||
|
|
||||
| if (e.keyCode === KEY_CODES.ESCAPE) { | ||||
| setProps({ is_focused: false }); | ||||
|
|
@@ -452,8 +453,6 @@ export default class ControlledTable extends Component<ControlledTableProps> { | |||
| } = this.props; | ||||
| const dataframe = virtualizer.dataframe; | ||||
|
|
||||
| e.preventDefault(); | ||||
|
|
||||
| const columnIndexOffset = | ||||
| (row_deletable ? 1 : 0) + | ||||
| (row_selectable ? 1 : 0); | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,14 @@ describe('navigate', () => { | |
| }); | ||
| }); | ||
|
|
||
| // Issue: https://github.com/plotly/dash-table/issues/49 | ||
| it.only('can move after ctrl+c', () => { | ||
| DOM.focused.type(`${Key.Meta}c`); | ||
| DOM.focused.type(Key.ArrowDown); | ||
| DashTable.getCell(4, 3).should('have.class', 'focused'); | ||
| DashTable.getCell(3, 3).should('not.have.class', 'focused'); | ||
| }); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test makes sure that we can navigate out of the cell once Ctrl+C has been pressed |
||
|
|
||
| it('can move down', () => { | ||
| DOM.focused.type(Key.ArrowDown); | ||
| DashTable.getCell(4, 3).should('have.class', 'focused'); | ||
|
|
||
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.
The more this pops up the more I think we should keep track of custom vs default event handlers.
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.
Actually this one was already there, hidden away in onCopy, just made both consistent :)