diff --git a/docs/app/Examples/elements/Container/Types/ContainerExampleContainer.js b/docs/app/Examples/elements/Container/Types/ContainerExampleContainer.js
index 3f45a31c48..ee3ce5bbb2 100644
--- a/docs/app/Examples/elements/Container/Types/ContainerExampleContainer.js
+++ b/docs/app/Examples/elements/Container/Types/ContainerExampleContainer.js
@@ -1,12 +1,18 @@
-/* eslint-disable max-len */
-
import React from 'react'
-import { Container } from 'semantic-ui-react'
+import { Dropdown } from 'semantic-ui-react'
+
+const countryOptions = [
+ { key: 'af', value: 'af', flag: 'af', text: 'Afghanistan' },
+ { key: 'ae', value: 'ae', flag: 'ae', text: 'United Arab Emirates' },
+ { key: 'us', value: 'us', flag: 'us', text: 'United States' },
+]
-const ContainerExampleContainer = () => (
-
- 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.
-
+const DropdownExampleSearchSelection = () => (
+
+
+
+
+
)
-export default ContainerExampleContainer
+export default DropdownExampleSearchSelection
diff --git a/src/modules/Dropdown/Dropdown.js b/src/modules/Dropdown/Dropdown.js
index 5e4fd12e98..0e55c2a996 100644
--- a/src/modules/Dropdown/Dropdown.js
+++ b/src/modules/Dropdown/Dropdown.js
@@ -332,19 +332,19 @@ export default class Dropdown extends Component {
static defaultProps = {
additionLabel: 'Add ',
additionPosition: 'top',
+ closeOnBlur: true,
icon: 'dropdown',
+ minCharacters: 1,
noResultsMessage: 'No results found.',
+ openOnFocus: true,
renderLabel: ({ text }) => text,
selectOnBlur: true,
- openOnFocus: true,
- closeOnBlur: true,
- minCharacters: 1,
}
static autoControlledProps = [
'open',
- 'value',
'selectedLabel',
+ 'value',
]
static _meta = {
@@ -418,9 +418,11 @@ export default class Dropdown extends Component {
if (!prevState.focus && this.state.focus) {
debug('dropdown focused')
if (!this.isMouseDown) {
- const { openOnFocus } = this.props
+ const { minCharacters, openOnFocus, search } = this.props
+ const openable = !search || (search && minCharacters === 1)
+
debug('mouse is not down, opening')
- if (openOnFocus) this.open()
+ if (openOnFocus && openable) this.open()
}
if (!this.state.open) {
document.addEventListener('keydown', this.openOnArrow)
@@ -578,11 +580,13 @@ export default class Dropdown extends Component {
}
selectItemOnEnter = (e) => {
- debug('selectItemOnEnter()')
- debug(keyboardKey.getName(e))
+ debug('selectItemOnEnter()', keyboardKey.getName(e))
+ const { search } = this.props
+
if (keyboardKey.getCode(e) !== keyboardKey.Enter) return
e.preventDefault()
+ if (search && _.isEmpty(this.getMenuOptions())) return
this.makeSelectedItemActive(e)
this.closeOnChange(e)
}
@@ -622,29 +626,34 @@ export default class Dropdown extends Component {
handleMouseDown = (e) => {
debug('handleMouseDown()')
- const { onMouseDown } = this.props
- if (onMouseDown) onMouseDown(e, this.props)
+
this.isMouseDown = true
+ _.invoke(this.props, 'onMouseDown', e, this.props)
// Do not access document when server side rendering
- if (!isBrowser) return
- document.addEventListener('mouseup', this.handleDocumentMouseUp)
+ if (isBrowser) document.addEventListener('mouseup', this.handleDocumentMouseUp)
}
handleDocumentMouseUp = () => {
debug('handleDocumentMouseUp()')
+
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)
}
- handleClick = (e) => {
+ handleClick = e => {
debug('handleClick()', e)
- const { onClick } = this.props
- if (onClick) onClick(e, this.props)
+
+ const { minCharacters, search } = this.props
+ const { open, searchQuery } = this.state
+
+ _.invoke(this.props, 'onClick', e, this.props)
// prevent closeOnDocumentClick()
e.stopPropagation()
- this.toggle(e)
+
+ if (!search) return this.toggle(e)
+ if (open) return
+ if (searchQuery.length >= minCharacters || minCharacters === 1) this.open(e)
}
handleItemClick = (e, item) => {
@@ -681,14 +690,15 @@ export default class Dropdown extends Component {
handleFocus = (e) => {
debug('handleFocus()')
- const { onFocus } = this.props
const { focus } = this.state
+
if (focus) return
- if (onFocus) onFocus(e, this.props)
+
+ _.invoke(this.props, 'onFocus', e, this.props)
this.setState({ focus: true })
}
- handleBlur = (e) => {
+ handleBlur = e => {
debug('handleBlur()')
// Heads up! Don't remove this.
@@ -707,26 +717,28 @@ export default class Dropdown extends Component {
this.setState({ focus: false, searchQuery: '' })
}
- handleSearchChange = (e) => {
- debug('handleSearchChange()')
- debug(e.target.value)
+ handleSearchChange = e => {
+ debug('handleSearchChange()', e)
// prevent propagating to this.props.onChange()
e.stopPropagation()
- const { search, onSearchChange, minCharacters } = this.props
- const { open } = this.state
- const newQuery = e.target.value
- if (onSearchChange) onSearchChange(e, newQuery)
+ const { minCharacters } = this.props
+ const { open } = this.state
+ const newQuery = _.get(e, 'target.value', '')
- if (newQuery.length >= minCharacters) {
- // open search dropdown on search query
- if (search && newQuery && !open) this.open()
+ _.invoke(this.props, 'onSearchChange', e, newQuery)
+ this.setState({
+ selectedIndex: 0,
+ searchQuery: newQuery,
+ })
- this.setState({
- selectedIndex: 0,
- searchQuery: newQuery,
- })
+ // open search dropdown on search query
+ if (!open && newQuery.length >= minCharacters) {
+ this.open()
+ return
}
+ // close search dropdown if search query is too small
+ if (open && minCharacters !== 1 && newQuery.length < minCharacters) this.close()
}
// ----------------------------------------