Skip to content

NetSim: Stable sent-by dropdown#9816

Merged
islemaster merged 5 commits into
stagingfrom
netsim-stable-sent-by-dropdown
Aug 4, 2016
Merged

NetSim: Stable sent-by dropdown#9816
islemaster merged 5 commits into
stagingfrom
netsim-stable-sent-by-dropdown

Conversation

@islemaster

Copy link
Copy Markdown
Contributor

@sfilman noticed another problem with the new Teacher View sent-by dropdown (original report):

The dropdown automatically closes when a new message arrives, which i think would be annoying and possibly prevent selecting a student low on the list.

This PR contains a fix for that issue, and a good chunk of cleanup I did while stumbling around trying to find the fix. See inline comments to explain what's what, or see individual commits.

BaseDialog is configured to take focus any time it is rendered to make sure pressing ESC to close the dialog works.  However, when the dialog is already open and a full dialog update/re-render occurs, this can steal focus from form fields within the dialog.  This makes the dialog check whether one of its descendants already has focus before it steals focus for itself.
const descendantIsActive = document.activeElement && this.refs.dialog &&
this.refs.dialog.contains(document.activeElement);
if (this.props.isOpen && !descendantIsActive) {
this.refs.dialog.focus();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the actual fix for the reported bug. The BaseDialog component steals focus every time it's rendered, to make sure the Esc key can close the dialog. This produced an undesirable behavior when the dialog was open and contained form fields - the fields would lose focus on every re-render, as the dialog itself claimed it at the end of the render process. Thanks @Bjvanminnen for putting me on the right track here.

The solution is to check whether a descendant of the dialog already has focus, and do nothing in that case.

@Bjvanminnen

Copy link
Copy Markdown
Contributor

one comment, otherwise lgtm

return {
...newProps,
originalClassName,
className: originalClassName,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This fixes a warning for unknown properties on DOM elements, introduced in React 15.2.0.

@islemaster islemaster merged commit a65bdc6 into staging Aug 4, 2016
@islemaster islemaster deleted the netsim-stable-sent-by-dropdown branch August 4, 2016 20:33
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