-
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
feat(Dropdown): add openOnFocus
and closeOnBlur
#1101
Conversation
@levithomason This PR seems a little vague as of now since I don't have a 100% understanding of the exact issue. But what I did was added the two props to the |
Current coverage is 95.87% (diff: 100%)
|
@@ -296,6 +296,10 @@ export default class Dropdown extends Component { | |||
/** The text displayed in the dropdown, usually for the active item. */ | |||
text: PropTypes.string, | |||
|
|||
openOnFocus: PropTypes.bool, |
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 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."
Now, the The same is true for the Both of these new props should be added to We should also have two new doc examples, one for each prop. These would go in the "Usage" section. Finally, we'll add some tests after all this is done. |
So, what's the difference between the menu and the dropdown? The menu is in the dropdown? So basically open the dropdown when the user focusses it by tabbing to it? And close the dropdown when you tab away? |
… and closeOnBlur props
@levithomason let me know how this PR looks as of now. Time permitting, could you clarify my questions above? |
Correct.
Exactly. These features already exist, however, they are always "on" and there is no way to turn them off. This PR is adding the ability to turn them off. On this note, the logic should actually be added to the |
So the logic added to the open & close methods currently is incorrect? |
Indeed, my mistake on the initial instructions. The goal is to allow the user to enable/disable this behavior. My suggestion would be to get the doc examples written and wired up, then play with them until you feel it is working correctly. I can then review the progress. I thought I'd have more time to dive into this and give guidance, however, it would help me if you could push some further attempts at it on your own and I'll try to help guide you. |
No worries. Hope my questions weren't too silly! I'll have some example for you ready in a few hours. |
@levithomason Hi! I've made the changes and added example in the last three commits. Please could you review these for me? 💯 |
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.
Just had a new 👶 so might be a little slow on follow up, but I managed to get some reviews in on this. We're getting real close, thanks much!
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Let's show both cases here as well.
import { friendOptions } from '../common' | ||
|
||
const DropdownExampleCloseOnBlur = () => ( | ||
<Dropdown placeholder='Select Friend' closeOnBlur fluid selection options={friendOptions} /> |
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?
<div>
<Dropdown
closeOnBlur
options={friendOptions}
placeholder='I close on blur'
selection
/>
{' '}
<Dropdown
closeOnBlur={false}
options={friendOptions}
placeholder='I stay open on blur'
selection
/>
</div>
debug('mouse is not down, opening') | ||
if (!openOnFocus) return |
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.
Small syntactical change request: if (openOnFocus) this.open()
, since there is an explicit 1:1 correlation between the condition and the action in this case.
debug('mouse is not down, closing') | ||
if (!closeOnBlur) return |
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.
Same here: if (closeOnBlur) this.close()
.
…penOnFocus and closeOnBlue props to docs site
@levithomason Congratulations on the 👶! Hope he/she is doing well! i've made the changes in the last commit. I also have a .mov file that I created to show how it's working currently. Don't think Github supports that, where would be the best place to send you that file? I also see this error when I use the arrow keys to move through the menu items. Here's a screenshot of that specific error. |
@@ -3,7 +3,11 @@ import { Dropdown } from 'semantic-ui-react' | |||
import { friendOptions } from '../common' | |||
|
|||
const DropdownExampleOpenOnFocus = () => ( | |||
<Dropdown placeholder='Select Friend' openOnFocus fluid selection options={friendOptions} /> | |||
<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 comment
The reason will be displayed to describe this comment to others. Learn more.
-I stay open on focus
+I open on focus
<div> | ||
<Dropdown placeholder='I stay open on focus' openOnFocus fluid selection options={friendOptions} /> | ||
<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 comment
The reason will be displayed to describe this comment to others. Learn more.
-I close when not focussed
+I do not open on focus
<Dropdown placeholder='Select Friend' closeOnBlur fluid selection options={friendOptions} /> | ||
<div> | ||
<Dropdown placeholder='I close on blur' closeOnBlur fluid selection options={friendOptions} /> | ||
<br /> |
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.
Thanks for the updates, I'll pull this branch down and give it a go as soon as I am able. I left a couple more comments for now 👍 Thanks again. |
…d better placeholders
@levithomason Done! Just made the changes you suggested. |
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 comment
The 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 comment
The 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 comment
The 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 closeOnBlur
being true, and tab out of it to the adjacent one, the first one closes. It shouldn't right?
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Perfect thank you! |
openOnFocus
and closeOnBlur
@levithomason what about tests? 😸 |
Released in Yes, tests would be great. Didn't want to hold this one up too much longer for you, since there are tests covering the basic use already. If you want to start a new PR for that, we just need to copy some of the existing tests and update then to work for this case 👍 |
Cool, any example tests I could look at for this? The other test case was kind of easy since I just had to check if the component had the class name appended to it. Not the case for this one, right? |
We add a |
Sounds good. Did you get a chance to review this comment? Alright, hmm. I'm seeing something weird. When I go to the dropdown with closeOnBlur being true, and tab out of it to the adjacent one, the first one closes. It shouldn't right? |
Just beat me to it! Was about to comment the same. I checked the source as well, not sure right off hand why that is. Let's investigate and fix it on the next PR. |
wait a sec, shouldn't it be an if else statement. And in the else, just do |
@@ -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 comment
The 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?
Fixes #517