-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
fix(Dropdown): retains focus after selection #3452
fix(Dropdown): retains focus after selection #3452
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3452 +/- ##
==========================================
+ Coverage 99.83% 99.83% +<.01%
==========================================
Files 175 175
Lines 3120 3121 +1
==========================================
+ Hits 3115 3116 +1
Misses 5 5
Continue to review full report at Codecov.
|
src/lib/AutoControlledComponent.js
Outdated
*/ | ||
trySetState = (maybeState, state) => { | ||
trySetState = (maybeState, state, callback = () => {}) => { |
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.
Thanks for this, I'd been wanting to update this to match React's API. There are only a few cases where we use the state
argument as well. I'm thinking we should also remove it to match the React API 1:1. Otherwise, to use the callback you need to pass some null state
:
this.trySetState(
{ count: 1 }, // maybeState
null, // state, I don't need...
() => console.log('done') // complete callback
)
The current trySetState
implementation throws warnings about including state keys that are not listed in autoControlledProps
, however, it could instead ignore them and include them as-is in the actual setState
call. This way we can just combine the maybe state and the actual state.
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.
I tried to remove the state
arguments out of trySetState
.
I'm not sure I did understand what you said.
please review this code again
src/modules/Dropdown/Dropdown.js
Outdated
@@ -489,7 +489,7 @@ export default class Dropdown extends Component { | |||
const { closeOnChange, multiple } = this.props | |||
const shouldClose = _.isUndefined(closeOnChange) ? !multiple : closeOnChange | |||
|
|||
if (shouldClose) this.close(e) | |||
if (shouldClose) this.close(e, () => {}) |
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.
cruft?
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.
This is on purpose.
callback
the 2nd argument in close
method has default value.
But not using default value in this case.
close = (e, callback = this.handleClose) => {
const { open } = this.state
debug('close()', { open })
if (open) {
_.invoke(this.props, 'onClose', e, this.props)
this.trySetState({ open: false }, callback)
}
}
src/modules/Dropdown/Dropdown.js
Outdated
const { open } = this.state | ||
debug('close()', { open }) | ||
|
||
if (open) { | ||
_.invoke(this.props, 'onClose', e, this.props) | ||
this.trySetState({ open: false }) | ||
this.trySetState({ open: false }, undefined, callback) |
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.
Case-in-point 😉
I also merged master and fixed conflicts here. You'll need to pull before resuming work. |
I tried adding ‘active’ class on Dropdown when ‘focus’ state is true. |
Any update on this? Would save a lot of effort... |
@levithomason could you review this again please ? |
Yep, that blue border is a CSS issue, want to check this additionally. For the late feedback 🐑 |
…React into fix-dropdown-focus-after-selection # Conflicts: # src/lib/AutoControlledComponent.js
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.
Tested it manually, works perfectly 👍
Fixes #3349.
@layershifter Could you please review this one?