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

fix(Dropdown): retains focus after selection #3452

Merged

Conversation

jongsue
Copy link
Contributor

@jongsue jongsue commented Feb 22, 2019

Fixes #3349.

@layershifter Could you please review this one?

@codecov-io
Copy link

codecov-io commented Feb 22, 2019

Codecov Report

Merging #3452 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3452      +/-   ##
==========================================
+ Coverage   99.83%   99.83%   +<.01%     
==========================================
  Files         175      175              
  Lines        3120     3121       +1     
==========================================
+ Hits         3115     3116       +1     
  Misses          5        5
Impacted Files Coverage Δ
src/modules/Dropdown/Dropdown.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0d66fa7...0beff78. Read the comment docs.

*/
trySetState = (maybeState, state) => {
trySetState = (maybeState, state, callback = () => {}) => {
Copy link
Member

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.

Copy link
Contributor Author

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

@@ -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, () => {})
Copy link
Member

Choose a reason for hiding this comment

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

cruft?

Copy link
Contributor Author

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)
    }
  }

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)
Copy link
Member

Choose a reason for hiding this comment

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

Case-in-point 😉

@levithomason
Copy link
Member

After making a selection in a search selection, the input DOM node retains focus but the Dropdown loses its blue border. I'm pretty sure this means this.state.focus is not true.

After making a selection:
image

Note the missing blue border, as there is when first focusing the Dropdown:
image

@levithomason
Copy link
Member

⚠️ Heads Up!

I also merged master and fixed conflicts here. You'll need to pull before resuming work.

@jongsue
Copy link
Contributor Author

jongsue commented Mar 13, 2019

After making a selection in a search selection, the input DOM node retains focus but the Dropdown loses its blue border. I'm pretty sure this means this.state.focus is not true.

After making a selection:
image

Note the missing blue border, as there is when first focusing the Dropdown:
image

semantic.css .ui.selection.dropdown:focus seems to make the blue border.

스크린샷 2019-03-14 오전 1 00 31

As you mentioned After making a selection in a search selection, the input DOM node retains focus not Dropdown.
That's why there is no blue border.
I don't know how to solve this problem. do you have any idea?

@jongsue
Copy link
Contributor Author

jongsue commented Mar 13, 2019

I tried adding ‘active’ class on Dropdown when ‘focus’ state is true.
Then we could get the blue border but there is ‘border-bottom-left-radius’ to make it look like not right

@amrita-syn
Copy link

Any update on this? Would save a lot of effort...

@jongsue
Copy link
Contributor Author

jongsue commented Apr 22, 2019

@levithomason could you review this again please ?
The blue border is css issues.
If Semantic UI would fix the problem then It'll fix ours too.

@layershifter
Copy link
Member

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/modules/Dropdown/Dropdown.js
…React into fix-dropdown-focus-after-selection

# Conflicts:
#	examples/webpack3/config/paths.js
#	examples/webpack3/src/components/Navbar/Navbar.js
…React into fix-dropdown-focus-after-selection

# Conflicts:
#	src/lib/AutoControlledComponent.js
Copy link
Member

@layershifter layershifter left a 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 👍

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

Successfully merging this pull request may close these issues.

Dropdown: focus is lost after selection
5 participants