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

feat(Dropdown): add openOnFocus and closeOnBlur #1101

Merged
merged 10 commits into from
Jan 11, 2017

Conversation

tarang9211
Copy link
Contributor

@tarang9211 tarang9211 commented Dec 31, 2016

Fixes #517

@tarang9211
Copy link
Contributor Author

@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 Dropdown.js file. Let me know what additional changes to make and I'll be more than happy to implement and learn!

@codecov-io
Copy link

codecov-io commented Dec 31, 2016

Current coverage is 95.87% (diff: 100%)

No coverage report found for master at 75be304.

Powered by Codecov. Last update 75be304...23f389f

@@ -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,
Copy link
Member

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."

@levithomason
Copy link
Member

levithomason commented Dec 31, 2016

Now, the open method needs to return early if openOnFocus is false. Similar to how it currently exits early if disabled.

The same is true for the close method and closeOnBlur.

Both of these new props should be added to defaultProps and set to true. This way, the current behavior is preserved.

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.

@tarang9211
Copy link
Contributor Author

tarang9211 commented Jan 1, 2017

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?

@tarang9211
Copy link
Contributor Author

@levithomason let me know how this PR looks as of now. Time permitting, could you clarify my questions above?

@levithomason
Copy link
Member

So, what's the difference between the menu and the dropdown? The menu is in the dropdown?

Correct.

So basically open the dropdown when the user focusses it by tabbing to it?
And close the dropdown when you tab away?

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 componentDidUpdate where it is calling open/close on focus/blur:

https://github.com/tarang9211/Semantic-UI-React/blob/35bd319e09132096c6fa3f2844c4f29bf36e9005/src/modules/Dropdown/Dropdown.js#L405

https://github.com/tarang9211/Semantic-UI-React/blob/35bd319e09132096c6fa3f2844c4f29bf36e9005/src/modules/Dropdown/Dropdown.js#L419

@tarang9211
Copy link
Contributor Author

So the logic added to the open & close methods currently is incorrect?

@levithomason
Copy link
Member

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.

@tarang9211
Copy link
Contributor Author

No worries. Hope my questions weren't too silly! I'll have some example for you ready in a few hours.

@tarang9211
Copy link
Contributor Author

@levithomason Hi! I've made the changes and added example in the last three commits. Please could you review these for me? 💯

Copy link
Member

@levithomason levithomason left a 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} />
Copy link
Member

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} />
Copy link
Member

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

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

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
@tarang9211
Copy link
Contributor Author

tarang9211 commented Jan 10, 2017

@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.
screen shot 2017-01-10 at 12 27 06 pm

@@ -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} />
Copy link
Member

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} />
Copy link
Member

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

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.

@levithomason
Copy link
Member

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.

@tarang9211
Copy link
Contributor Author

@levithomason Done! Just made the changes you suggested.

debug('mouse is not down, closing')
this.close()
if (closeOnBlur) this.close()
Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

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()
Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

👍

@levithomason
Copy link
Member

Perfect thank you!

@levithomason levithomason changed the title feat(Dropdown): added two more props to Dropdown component feat(Dropdown): add openOnFocus and closeOnBlur Jan 11, 2017
@levithomason levithomason merged commit d6cdabb into Semantic-Org:master Jan 11, 2017
@tarang9211
Copy link
Contributor Author

@levithomason what about tests? 😸

@levithomason
Copy link
Member

Released in semantic-ui-react@0.63.6.

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 👍

@tarang9211
Copy link
Contributor Author

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?

@levithomason
Copy link
Member

We add a describe() block for each prop, so describe('openOnFocus', () => { ... }) for example. Then you can find other focus/blur tests and use those for inspiration. Example:

https://github.com/Semantic-Org/Semantic-UI-React/blob/master/test/specs/modules/Dropdown/Dropdown-test.js#L150

@tarang9211
Copy link
Contributor Author

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?

@levithomason
Copy link
Member

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.

@tarang9211
Copy link
Contributor Author

wait a sec, shouldn't it be an if else statement. And in the else, just do this.open()?

@@ -409,8 +418,9 @@ export default class Dropdown extends Component {
} else if (prevState.focus && !this.state.focus) {
debug('dropdown blurred')
if (!this.isMouseDown) {
Copy link

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?

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

Successfully merging this pull request may close these issues.

4 participants