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): fix minCharacter prop behaviour #1722

Merged
merged 3 commits into from
Jun 22, 2017

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented May 31, 2017

Fixes #1718.

Behaviours

This PR fixes issues with minCharacters and also some other inconsistent things.

TODO

  • onClick
  • onClick (toogle)
  • onFocus
  • onChange
  • onChange (Enter)

onFocus (placeholder #1299, will be done in separate task)

onClick

Note, that if you click on input after it was openned, you will not close it, e.g. click don't toggle searchable dropdown.

minCharacters = 1

peek 2017-06-01 16-41

minCharacters = 3

Dropdown wasn't openned after click.

peek 2017-06-01 16-49

onFocus

minCharacters = 1

Note, focus doesn't affect placeholder. After focus was lost first item was selected, because item was focused.

minCharacters = 1

peek 2017-06-01 16-47

minCharacters = 3

Dropdown wasn't openned after click.

peek 2017-06-01 16-50

onChange

Note, is you have no results message and you click Enter key, nothing will be happened.

minCharacters = 1

peek 2017-06-01 16-52

minCharacters = 3

peek 2017-06-01 16-53

<Container>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa strong. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede link mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi.</p>
</Container>
const DropdownExampleSearchSelection = () => (
Copy link
Member

Choose a reason for hiding this comment

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

Whoops, this looks like the wrong content for this file.

Copy link
Member

Choose a reason for hiding this comment

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

Whoops, looks like I missed the big fat WIP 😊

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I will revert this before merge 😄

@codecov-io
Copy link

codecov-io commented Jun 1, 2017

Codecov Report

Merging #1722 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1722      +/-   ##
==========================================
- Coverage   99.75%   99.75%   -0.01%     
==========================================
  Files         142      142              
  Lines        2468     2464       -4     
==========================================
- Hits         2462     2458       -4     
  Misses          6        6
Impacted Files Coverage Δ
src/modules/Dropdown/Dropdown.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 62b0fd6...5f70d73. Read the comment docs.

@layershifter layershifter changed the title fix(Dropdown): fix minCharacter prop fix(Dropdown): fix minCharacter prop behaviour Jun 2, 2017
@layershifter
Copy link
Member Author

@levithomason I done everything except placeholder's behaviour. Let me know what you think about proposed changes in this PR, gifs were captured from SUI, you can compare them with our current docs. If it will okay, I'll add tests and prepare PR for merge.

noResultsMessage: 'No results found.',
openOnFocus: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

Only prop sort there.

debug('mouse is not down, opening')
if (openOnFocus) this.open()
if (openOnFocus && openable) this.open()
Copy link
Member Author

Choose a reason for hiding this comment

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

Defines behaviour with focus.

if (keyboardKey.getCode(e) !== keyboardKey.Enter) return
e.preventDefault()

if (search && _.isEmpty(this.getMenuOptions())) return
Copy link
Member Author

Choose a reason for hiding this comment

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

Disables Enter key when nothing find.

// Do not access document when server side rendering
if (!isBrowser) return
document.addEventListener('mouseup', this.handleDocumentMouseUp)
if (isBrowser) document.addEventListener('mouseup', this.handleDocumentMouseUp)
Copy link
Member Author

Choose a reason for hiding this comment

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

Minor refactor.

this.isMouseDown = false
// Do not access document when server side rendering
if (!isBrowser) return
document.removeEventListener('mouseup', this.handleDocumentMouseUp)
if (isBrowser) document.removeEventListener('mouseup', this.handleDocumentMouseUp)
Copy link
Member Author

Choose a reason for hiding this comment

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

Minor refactor.


if (!search) return this.toggle(e)
if (open) return
if (searchQuery.length >= minCharacters || minCharacters === 1) this.open(e)
Copy link
Member Author

Choose a reason for hiding this comment

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

Update behaviour with click on search input.

.simulate('change', { target: { value: faker.hacker.noun().substring(0, 1) } })

dropdownMenuIsClosed()
})
Copy link
Member Author

Choose a reason for hiding this comment

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

Test was moved to another section.

Copy link
Member Author

@layershifter layershifter left a comment

Choose a reason for hiding this comment

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

@levithomason We're ready for review there, will be awesome to hear your thoughts.

@timworx
Copy link

timworx commented Jun 6, 2017

Would be great to see this merged.

It fixes a considerable bug in handleSearchChange. Within that function setState happens in an if block that keeps it from being called when you're deleting the last character in the searchQuery.


this.close(e)
}
toggle = e => this.state.open ? this.close(e) : this.open(e)
Copy link
Member Author

@layershifter layershifter Jun 7, 2017

Choose a reason for hiding this comment

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

Method was updated because its logic was moved to handleClick

@layershifter
Copy link
Member Author

layershifter commented Jun 7, 2017

@timworx thanks for the feedback, I missed this problem, hovewer it's fixed.

Just a note, @levithomason I think you should ship this in 0.68.6, because it fixes critical bugs, without this PR the Dropdown with a search prop is completely unusable.

@layershifter
Copy link
Member Author

@levithomason please take an attention to this PR.

@levithomason
Copy link
Member

The next shipment (here in a few minutes) will be breaking because of #1730 which has already been merged. We won't update previous versions until we hit a stable 1.0 release. Bugs and features will be shipped as fast as possible without going backwards.

I'll demo this and see about shipping it now in 0.69.0.

@levithomason levithomason merged commit 9287f9c into master Jun 22, 2017
@levithomason levithomason deleted the fix/dropdown-minchars branch June 22, 2017 01:14
@levithomason
Copy link
Member

Released in semantic-ui-react@0.69.0

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.

Dropdown: minCharacters breaks search input
4 participants