Skip to content

[Fixed issue #464] #540

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

Merged
merged 3 commits into from
Oct 25, 2017

Conversation

kloots
Copy link

@kloots kloots commented Oct 23, 2017

Fixes #464.

Changes proposed:

  • Adds a new prop shouldReturnFocusAfterClose allowing explicit control over if a modal should restore focus to the element that had focus prior to its displayed.
  • Does not try to restore focus if focus wasn't transferred to the modal in the first place (shouldFocusAfterRender was set to false)
  • Fixes a typo in the Modal props so that shouldFocusAfter is now correctly shouldFocusAfterRender
  • Fixes a number of line-length warnings

Acceptance Checklist:

  • All commits have been squashed to one.
  • The commit message follows the guidelines in CONTRIBUTING.md.
  • Documentation (README.md) and examples have been updated as needed.
  • If this is a code change, a spec testing the functionality has been added.
  • If the commit message has [changed] or [removed], there is an upgrade path above.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 86.445% when pulling 9fe0b63 on kloots:add-prop-to-prevent-restoring-focus into 5f5c2f0 on reactjs:master.

@diasbruno
Copy link
Collaborator

Hi @kloots There are 3 PRs in one. If you can stack 3 commits, one for each fix, it will show up better on the log and changelog.

@diasbruno
Copy link
Collaborator

diasbruno commented Oct 23, 2017

[added] shouldReturnFocusAfterClose to control focus.
[fixed] correct property name shouldFocusAfterRender.
[chore] refactoring tests and lint.

Something like this.

@diasbruno
Copy link
Collaborator

...and thank you for taking a look on this.

@diasbruno
Copy link
Collaborator

This line also needs a condition ModalPortal.js#L151, otherwise the activeElement will be pushed on the focus stack and might cause troubles when open/close other modals (unlikely but possible).

@kloots kloots force-pushed the add-prop-to-prevent-restoring-focus branch from 9fe0b63 to 4999fce Compare October 24, 2017 00:56
@kloots
Copy link
Author

kloots commented Oct 24, 2017

@diasbruno All your suggestions are done, done and done

@kloots kloots force-pushed the add-prop-to-prevent-restoring-focus branch from 4999fce to c2f2ef5 Compare October 24, 2017 20:54
@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 86.514% when pulling c2f2ef5 on kloots:add-prop-to-prevent-restoring-focus into 5f5c2f0 on reactjs:master.

@kloots
Copy link
Author

kloots commented Oct 25, 2017

@diasbruno any reason this hasn't been merged yet? Asking because we need this for Slack.

@diasbruno
Copy link
Collaborator

@kloots @ilikepies101 I'd be in favor of the first PR, just because it was the first...but it seems that the other PR will need to be rebased and also this one is more complete. So, I'll merge this one.

Thank you both for working on this issue.

@diasbruno diasbruno merged commit 42d724c into reactjs:master Oct 25, 2017
@diasbruno
Copy link
Collaborator

Released v3.1.0.

// 2. Explicit direction to not restore focus
return (
this.props.shouldFocusAfterRender ||
this.props.shouldReturnFocusAfterClose
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this should be && not ||. Currently I have to pass both shouldFocusAfterRender={false} and shouldReturnFocusAfterClose={false} to opt out of refocusing.

Copy link
Collaborator

@diasbruno diasbruno Nov 6, 2017

Choose a reason for hiding this comment

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

Looking at this now, if shouldReturnFocusAfterClose=false, it would also disable the 'focus after render'. They must be independent.

Copy link
Collaborator

Choose a reason for hiding this comment

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

NOTES:

If shouldFocusAfterRender=true and shouldReturnFocusAfterClose=false, we put the element in the focus manager and on close we just pop it out.

shouldFocusAfterRender=false and shouldReturnFocusAfterClose=true must be noop just like shouldFocusAfterRender=false and shouldReturnFocusAfterClose=false.

shouldFocusAfterRender=true and shouldReturnFocusAfterClose=true is the default behavior.

Does this make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, sounds reasonable

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, what are the usecases for shouldFocusAfterRender? Looks like it just focuses a div without any keyboard handlers

Copy link
Collaborator

@diasbruno diasbruno Nov 6, 2017

Choose a reason for hiding this comment

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

To set the scope for tabbing, so it won't leave the modal when it's open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants