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): respect closeOnBlur={false} #1148

Merged

Conversation

tarang9211
Copy link
Contributor

No description provided.

@@ -420,7 +420,11 @@ export default class Dropdown extends Component {
if (!this.isMouseDown) {
const { closeOnBlur } = this.props
debug('mouse is not down, closing')
if (closeOnBlur) this.close()
if (closeOnBlur) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@levithomason this is what I meant. With this piece of code, when I tab away from this dropdown, it stays open until a user clicks somewhere else on the screen. Let me know your thoughts.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I'll mark this for review to investigate. I can't think of a reason we'd need to set open again when it is already open. Thanks for the note here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@levithomason sounds good. let me know how we can fix this.

@codecov-io
Copy link

codecov-io commented Jan 12, 2017

Current coverage is 95.88% (diff: 100%)

Merging #1148 into master will decrease coverage by <.01%

@@             master      #1148   diff @@
==========================================
  Files           879        879          
  Lines          4889       4883     -6   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits           4688       4682     -6   
  Misses          201        201          
  Partials          0          0          

Powered by Codecov. Last update d8045cf...c09ab6f

@tarang9211
Copy link
Contributor Author

@levithomason any idea what's going with the codecov failing?

@levithomason
Copy link
Member

Codecov is failing because there were new branches of logic added that do not have test cases.

https://github.com/Semantic-Org/Semantic-UI-React/blob/master/.github/CONTRIBUTING.md#coverage

@tarang9211
Copy link
Contributor Author

yea it complained about the if/else block not having code coverage.

@tarang9211
Copy link
Contributor Author

@levithomason Do we have any feedback or review on this?

@levithomason
Copy link
Member

I'll get a review on the functionality as is for now. However, this PR needs more coverage before it can be merged. The added branch logic needs a test, this is why Codecov is failing the PR.

@levithomason
Copy link
Member

OK, so the issue it turns out is that blurring calls handleBlur() which causes the selected item to become active in selectHighlightedItem(). This method would then close the Dropdown, if it is not a multiple Dropdown.

This logic flow worked fine before adding closeOnBlur. Instead, I've removed the close() logic from selectHighlightedItem() and that method only activates the item. I've explicitly called close() in selectItemOnEnter() and handleBlur() with the appropriate logic.

With this fix, we're able to avoid having to re-open the Dropdown on blur as was originally the case in this PR.

@@ -547,7 +547,6 @@ export default class Dropdown extends Component {
} else {
this.setValue(value)
this.handleChange(e, value)
this.close()
Copy link
Member

Choose a reason for hiding this comment

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

This was the bug, we were closing every time an item was activated. Even when closeOnBlur was false. Since, this method was called on blur due to blur activating the selected item.

@@ -902,9 +906,7 @@ export default class Dropdown extends Component {

scrollSelectedItemIntoView = () => {
debug('scrollSelectedItemIntoView()')
// Do not access document when server side rendering
if (!isBrowser) return
const menu = document.querySelector('.ui.dropdown.active.visible .menu.visible')
Copy link
Member

Choose a reason for hiding this comment

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

This fixes another bug. If multiple Dropdowns were open, this would select the first one on the page. This meant the Menu for a Dropdown not belonging to this one was being operated on.

I've fixed that by selecting this Dropdown's Menu.

@levithomason levithomason changed the title fix(Dropdown): possible solution for closeOnBlur prop bug fix(Dropdown): respect closeOnBlur={false} Jan 24, 2017
@levithomason levithomason merged commit 8ddc498 into Semantic-Org:master Jan 24, 2017
@tarang9211
Copy link
Contributor Author

@levithomason Ah ok that makes sense. I did notice that the dropdown was closing after making a selection on an item. Sounds good, thank you for the review and guidance!

@levithomason
Copy link
Member

Released in semantic-ui-react@0.64.4.

DomiR added a commit to DomiR/Semantic-UI-React that referenced this pull request Jan 26, 2017
* Semantic-Org/master: (111 commits)
  fix(docs): fix usage of arrow function (Semantic-Org#1228)
  fix(Icon): Incorrect definition in typings (Semantic-Org#1225)
  fix(Button): fix `tabIndex` in typings (Semantic-Org#1224)
  fix(typings): add item prop to the DropdownProps (Semantic-Org#1223)
  docs(examples): add missing `key` props (Semantic-Org#1220)
  docs(changelog): update changelog [ci skip]
  0.64.4
  feat(Form): add `inverted` prop (Semantic-Org#1218)
  fix(ComponentExample): use explicit babel presets (Semantic-Org#1219)
  style(Button): update typings and propTypes usage (Semantic-Org#1216)
  style(Embed): update typings and propTypes usage (Semantic-Org#1217)
  chore(package): support for jsnext:main (Semantic-Org#1210)
  style(Step): update typings, tests and propTypes usage (Semantic-Org#1203)
  fix(Portal): do not take focus after first render (Semantic-Org#1215)
  style(Table|mixed): update typings, tests and propTypes usage (Semantic-Org#1200)
  fix(Dropdown): use `item` instead of `as={Menu.Item}` (Semantic-Org#659)
  fix(Dropdown): respect `closeOnBlur={false}` (Semantic-Org#1148)
  style(Breadcrumb): update typings and propTypes usage (Semantic-Org#1209)
  style(Dimmer): update typings (Semantic-Org#1208)
  fix(Divider|FormInput): fix the broken typings (Semantic-Org#1179)
  ...
harel pushed a commit to harel/Semantic-UI-React that referenced this pull request Feb 18, 2017
* fix(Dropdown): possible solution for closeOnBlur prop bug

* fix(Dropdown): respect closeOnBlur={false}
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.

3 participants