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

Keyboard._restoreFocus() clears the active selection in 'extended' mode #902

Closed
wants to merge 1 commit into from
Closed

Keyboard._restoreFocus() clears the active selection in 'extended' mode #902

wants to merge 1 commit into from

Conversation

dmartin-gh
Copy link
Contributor

If the focused row/cell receives an update from the store, the existing selection will be cleared during the focus restoration process. This only affects the 'extended' selection mode.

This is easily reproducible in the dgrid/test/Selection.html page.

  1. Load the page and scroll down to the second grid titled A grid with cell-level selection (default selection mode of "extended").
  2. Hold SHIFT and make a selection from Row5,Col1 to Row0,Col1 (the first 5 vertical cells in the first column). You now have Row0,Col1 focused as it was the last one you clicked.
  3. Open the console and run gridCellNavigation.store.put(gridCellNavigation.store.get(1)). The selection remains intact.
  4. Now run gridCellNavigation.store.put(gridCellNavigation.store.get(0)). The selection is cleared and only Row0,Col1 remains selected.

When Keyboard._restoreFocus() runs, it fires the dgrid-cellfocusin event. Selection._extendedSelectionHandler() picks this up and clears the active selection.

@dmartin-gh
Copy link
Contributor Author

I've attached a potential fix for this behavior. The _restoreFocus() method now includes the previous target in the dgrid-cellfocusin event. The _extendedSelectionHandler() method now skips the clearSelection() call if the target of the event is the same as the old target. This does not affect _restoreFocus() calls where a sibling is now focused (the target changed).

A drawback to this is the change from focus() to _focusOnNode() in _restoreFocus(). Mixins that have overridden the focus() method will no longer get their code executed during focus restoration. An alternative solution is to allow event-muckery at the focus() API level via a second optional event argument.

@dmartin-gh
Copy link
Contributor Author

Has anyone had a chance to look at this?

@kfranqueiro
Copy link
Member

Not yet, sorry, but I hope to get a chance to look at this and one or two other PRs next week if time permits.

@kfranqueiro
Copy link
Member

To be honest, my first thought looking at this again is that I wonder if in-place re-focusing should even emit dgrid's focus events to begin with. As far as the user's concerned their focus didn't budge an inch, right? I imagine if we made the event not emit at all in that case, this problem would also go away?

@dmartin-gh
Copy link
Contributor Author

That's probably fine, as long as something else triggers the re-focus of the new row element under the covers.

Edit: Never mind, it's already been refocused at the point the event is emitted. Suppressing the event should just solve it.

@ghost ghost closed this in 783b1a8 May 19, 2014
@dmartin-gh dmartin-gh deleted the restore-focus-selection branch May 19, 2014 15:39
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants