-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Dropdown): add DropdownSearchInput component (#1619)
* feat(Dropdown): add DropdownSearchInput component * feat(Dropdown): add DropdownSearchInput component * feat(Dropdown): add DropdownSearchInput component * docs(Dropdown): add DropdownSearchInput example * style(typings): fix lint issue * style(Dropdown): style updates * style(Dropdown): remove style and width props * fix(Dropdown): update after merge * fix(Dropdown): update after merge
- Loading branch information
1 parent
7bcf191
commit e6cdac6
Showing
10 changed files
with
310 additions
and
50 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
docs/app/Examples/modules/Dropdown/Usage/DropdownExampleSearchInput.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react' | ||
import { Dropdown } from 'semantic-ui-react' | ||
|
||
const options = [ | ||
{ key: 100, text: '100', value: 100 }, | ||
{ key: 200, text: '200', value: 200 }, | ||
{ key: 300, text: '300', value: 300 }, | ||
{ key: 400, text: '400', value: 400 }, | ||
] | ||
|
||
const DropdownExampleSearchInput = () => ( | ||
<Dropdown | ||
search | ||
searchInput={{ type: 'number' }} | ||
selection | ||
options={options} | ||
placeholder='Select amount...' | ||
/> | ||
) | ||
|
||
export default DropdownExampleSearchInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as React from 'react'; | ||
|
||
export interface DropdownSearchInputProps { | ||
[key: string]: any; | ||
|
||
/** An element type to render as (string or function). */ | ||
as?: any; | ||
|
||
/** Additional classes. */ | ||
className?: string; | ||
|
||
/** A ref handler for input. */ | ||
inputRef?: (c: HTMLInputElement) => void; | ||
|
||
/** An input can receive focus. */ | ||
tabIndex?: number | string; | ||
|
||
/** The HTML input type. */ | ||
type?: string; | ||
|
||
/** Stored value. */ | ||
value?: number | string; | ||
} | ||
|
||
declare const DropdownSearchInput: React.ComponentClass<DropdownSearchInputProps>; | ||
|
||
export default DropdownSearchInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import cx from 'classnames' | ||
import _ from 'lodash' | ||
import PropTypes from 'prop-types' | ||
import React, { Component } from 'react' | ||
|
||
import { | ||
createShorthandFactory, | ||
customPropTypes, | ||
META, | ||
getUnhandledProps, | ||
} from '../../lib' | ||
|
||
/** | ||
* A search item sub-component for Dropdown component. | ||
*/ | ||
class DropdownSearchInput extends Component { | ||
static propTypes = { | ||
/** An element type to render as (string or function). */ | ||
as: customPropTypes.as, | ||
|
||
/** Additional classes. */ | ||
className: PropTypes.string, | ||
|
||
/** A ref handler for input. */ | ||
inputRef: PropTypes.func, | ||
|
||
/** An input can receive focus. */ | ||
tabIndex: PropTypes.oneOfType([ | ||
PropTypes.number, | ||
PropTypes.string, | ||
]), | ||
|
||
/** The HTML input type. */ | ||
type: PropTypes.string, | ||
|
||
/** Stored value. */ | ||
value: PropTypes.oneOfType([ | ||
PropTypes.number, | ||
PropTypes.string, | ||
]), | ||
} | ||
|
||
static defaultProps = { | ||
type: 'text', | ||
} | ||
|
||
static _meta = { | ||
name: 'DropdownSearchInput', | ||
parent: 'Dropdown', | ||
type: META.TYPES.MODULE, | ||
} | ||
|
||
handleChange = e => { | ||
const value = _.get(e, 'target.value') | ||
|
||
_.invoke(this.props, 'onChange', e, { ...this.props, value }) | ||
} | ||
|
||
handleRef = c => _.invoke(this.props, 'inputRef', c) | ||
|
||
render() { | ||
const { className, tabIndex, type, value } = this.props | ||
const classes = cx('search', className) | ||
const rest = getUnhandledProps(DropdownSearchInput, this.props) | ||
|
||
return ( | ||
<input | ||
{...rest} | ||
aria-autocomplete='list' | ||
autoComplete='off' | ||
className={classes} | ||
onChange={this.handleChange} | ||
ref={this.handleRef} | ||
tabIndex={tabIndex} | ||
type={type} | ||
value={value} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
DropdownSearchInput.create = createShorthandFactory(DropdownSearchInput, type => ({ type })) | ||
|
||
export default DropdownSearchInput |
Oops, something went wrong.