-
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 9 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,13 @@ | ||
import React from 'react' | ||
import { Dropdown } from 'semantic-ui-react' | ||
import { friendOptions } from '../common' | ||
|
||
const DropdownExampleCloseOnBlur = () => ( | ||
<div> | ||
<Dropdown placeholder='I close on blur' closeOnBlur fluid selection options={friendOptions} /> | ||
<br /> | ||
<Dropdown placeholder='I stay open on blur' closeOnBlur={false} fluid selection options={friendOptions} /> | ||
</div> | ||
) | ||
|
||
export default DropdownExampleCloseOnBlur |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
import { Dropdown } from 'semantic-ui-react' | ||
import { friendOptions } from '../common' | ||
|
||
const DropdownExampleOpenOnFocus = () => ( | ||
<div> | ||
<Dropdown placeholder='I stay open on focus' 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. -I stay open on focus
+I open on focus |
||
<br /> | ||
<Dropdown placeholder='I close when not focussed' openOnFocus={false} 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. -I close when not focussed
+I do not open on focus |
||
</div> | ||
) | ||
|
||
export default DropdownExampleOpenOnFocus |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,6 +296,12 @@ export default class Dropdown extends Component { | |
/** The text displayed in the dropdown, usually for the active item. */ | ||
text: PropTypes.string, | ||
|
||
/** Whether or not the menu should open when the dropdown is focused. */ | ||
openOnFocus: PropTypes.bool, | ||
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 add some descriptions to these: "Whether or not the menu should open when the dropdown is focused." And: "Whether or not the menu should close when the dropdown is blurred." |
||
|
||
/** Whether or not the menu should close when the dropdown is blurred. */ | ||
closeOnBlur: PropTypes.bool, | ||
|
||
/** Custom element to trigger the menu to become visible. Takes place of 'text'. */ | ||
trigger: customPropTypes.every([ | ||
customPropTypes.disallow(['selection', 'text']), | ||
|
@@ -320,6 +326,8 @@ export default class Dropdown extends Component { | |
noResultsMessage: 'No results found.', | ||
renderLabel: ({ text }) => text, | ||
selectOnBlur: true, | ||
openOnFocus: true, | ||
closeOnBlur: true, | ||
} | ||
|
||
static autoControlledProps = [ | ||
|
@@ -395,8 +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') | ||
this.open() | ||
if (openOnFocus) this.open() | ||
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. Does this line look fine to you, logically? 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. 👍 |
||
} | ||
if (!this.state.open) { | ||
document.addEventListener('keydown', this.openOnArrow) | ||
|
@@ -409,8 +418,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') | ||
this.close() | ||
if (closeOnBlur) this.close() | ||
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. Does this line look fine to you, logically? 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. 👍 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. Alright, hmm. I'm seeing something weird. When I go to the dropdown with |
||
} | ||
document.removeEventListener('keydown', this.openOnArrow) | ||
document.removeEventListener('keydown', this.openOnSpace) | ||
|
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.
Let's drop the
fluid
prop and go with{' '}
here so these are inline elements rather than full page vertically stacked elements. Just helps keep the docs more concise.