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

Don't autofocus if the entire react-data-grid is offscreen #704

Conversation

theunixbeard
Copy link

@theunixbeard theunixbeard commented Mar 20, 2017

Description

Due to the current autofocus behavior, when the react-data-grid is rerendered the scroll bar 'jumps' up to put the focused cell in view, even if it was a completely different section of the UI that caused the underlying data to change. This would more often occur in applications with complex UIs such as the one I am working on.

I created a short 1-minute video demonstrating the issue & explaining my fix:
https://www.youtube.com/watch?v=xejQdVGJX6w

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (check one with "x")

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior? (You can also link to an open issue here)
When the react-data-grid is rerendered the scroll bar 'jumps' up to put the focused cell in view, even if it was a completely different section of the UI that caused the underlying data to change.

What is the new behavior?
In the isFocusedOnBody() method in Cell.js, we simply check if the dataGridDOMNode is currently on screen or off screen. If it's off screen, then don't trigger the autofocus.

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[x] No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information:
Tests have been added. I also ran the linter and that gave a clean output too.

Thanks for taking a look at this PR!

@jpdriver
Copy link
Contributor

@theunixbeard thanks for opening such a detailed PR!

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 716060c on theunixbeard:dont-autofocus-from-offscreen into ** on adazzle:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 716060c on theunixbeard:dont-autofocus-from-offscreen into ** on adazzle:master**.

@supamanda
Copy link
Contributor

Good idea. I think it would make more sense to call the method 'isTableOnScreen` or something like that, rather than tying it in with the isFocusedOnBody method

Also see issue #714 - i think it should not autofocus when it's focused on the body because chrome & firefox set focus to body during blur which means it may steal focus from other parts of the page, even though it has no business doing so.

@theunixbeard theunixbeard force-pushed the dont-autofocus-from-offscreen branch 2 times, most recently from 4772db0 to 643ace7 Compare April 12, 2017 04:27
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 643ace7 on theunixbeard:dont-autofocus-from-offscreen into ** on adazzle:master**.

@theunixbeard theunixbeard force-pushed the dont-autofocus-from-offscreen branch 4 times, most recently from 9c0d2f4 to e3538cb Compare April 21, 2017 10:53
@theunixbeard theunixbeard force-pushed the dont-autofocus-from-offscreen branch from e3538cb to 28bbe86 Compare April 21, 2017 10:56
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 28bbe86 on theunixbeard:dont-autofocus-from-offscreen into ** on adazzle:master**.

return false;
},

isFocusedOnBody(dataGridDOMNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

hi @theunixbeard , it would be better if you changed this back to the original isFocusedOnBody function, and then...

@@ -363,7 +379,7 @@ const Cell = React.createClass({
// Only focus to the current cell if the currently active node in the document is within the data grid.
// Meaning focus should not be stolen from elements that the grid doesnt control.
let dataGridDOMNode = this.props.cellMetaData && this.props.cellMetaData.getDataGridDOMNode ? this.props.cellMetaData.getDataGridDOMNode() : null;
if (this.isFocusedOnCell() || this.isFocusedOnBody() || (dataGridDOMNode && dataGridDOMNode.contains(document.activeElement))) {
if (this.isFocusedOnCell() || this.isFocusedOnBody(dataGridDOMNode) || (dataGridDOMNode && dataGridDOMNode.contains(document.activeElement))) {
Copy link
Contributor

@supamanda supamanda Apr 30, 2017

Choose a reason for hiding this comment

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

... change this if statement to include || this.isFocusedOnBody() || this.isTableOnScreen(dataGridDOMNode)

(Or better still remove this.isFocusedOnBody() altogether.)

@malonecj
Copy link
Contributor

Closing this issue, as auto focus will be removed in v 4.0 of the grid. The plan is to move the responsibility of cell section out of the Cell component and into a dedicated SelectionMask that sits at canvas level. This will provide the following benefits

  • Increased performance as navigating will result in minimal state tree changes
  • Prevent grid stealing focus from other elements
    You can see progress here

@malonecj malonecj closed this Feb 12, 2018
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.

5 participants