-
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
feat(Dropdown): add openOnFocus
and closeOnBlur
#1101
Changes from 3 commits
510afda
a0a5963
e23854e
69aeee2
35bd319
33fcd85
eac7c8f
f08de41
23f389f
b002a52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
import { Dropdown } from 'semantic-ui-react' | ||
import { friendOptions } from '../common' | ||
|
||
const DropdownExampleCloseOnBlur = () => ( | ||
<Dropdown placeholder='Select Friend' closeOnBlur fluid selection options={friendOptions} /> | ||
) | ||
|
||
export default DropdownExampleCloseOnBlur |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
import { Dropdown } from 'semantic-ui-react' | ||
import { friendOptions } from '../common' | ||
|
||
const DropdownExampleOpenOnFocus = () => ( | ||
<Dropdown placeholder='Select Friend' openOnFocus fluid selection options={friendOptions} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's show both cases here as well. |
||
) | ||
|
||
export default DropdownExampleOpenOnFocus |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -403,7 +403,9 @@ export default class Dropdown extends Component { | |
if (!prevState.focus && this.state.focus) { | ||
debug('dropdown focused') | ||
if (!this.isMouseDown) { | ||
const { openOnFocus } = this.props | ||
debug('mouse is not down, opening') | ||
if (!openOnFocus) return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small syntactical change request: |
||
this.open() | ||
} | ||
if (!this.state.open) { | ||
|
@@ -417,7 +419,9 @@ export default class Dropdown extends Component { | |
} else if (prevState.focus && !this.state.focus) { | ||
debug('dropdown blurred') | ||
if (!this.isMouseDown) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey guys I know I'm late to the party. I wanted to discuss this line with you. So I'm doing a search Dropdown and I don't want it to open on focus. This works fine while tabbing through the form, but clicking on a form field is also focusing on it, yet it'll still open. It makes sense that the menu opens if you click on the arrow, but I think for search it's a bit unintuitive if it opens when one clicks on the input. Thoughts? |
||
const { closeOnBlur } = this.props | ||
debug('mouse is not down, closing') | ||
if (!closeOnBlur) return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: |
||
this.close() | ||
} | ||
document.removeEventListener('keydown', this.openOnArrow) | ||
|
@@ -919,9 +923,8 @@ export default class Dropdown extends Component { | |
open = (e) => { | ||
debug('open()') | ||
|
||
const { disabled, onOpen, search, openOnFocus } = this.props | ||
const { disabled, onOpen, search } = this.props | ||
if (disabled) return | ||
if (!openOnFocus) return | ||
if (search && this._search) this._search.focus() | ||
if (onOpen) onOpen(e, this.props) | ||
|
||
|
@@ -931,8 +934,7 @@ export default class Dropdown extends Component { | |
close = (e) => { | ||
debug('close()') | ||
|
||
const { onClose, closeOnBlur } = this.props | ||
if (!closeOnBlur) return | ||
const { onClose } = this.props | ||
if (onClose) onClose(e, this.props) | ||
|
||
this.trySetState({ open: false }) | ||
|
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.
How about we show both true/false cases for comparison?