Skip to content

Commit

Permalink
Merge pull request #54 from vinnymac/features/autofocus
Browse files Browse the repository at this point in the history
add prop to autofocus search input
  • Loading branch information
EtienneLem committed Apr 4, 2017
2 parents b4f39a2 + ba38820 commit 3c78aee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Picker } from 'emoji-mart'

| Prop | Required | Default | Description |
| ---- | :------: | ------- | ----------- |
| **autoFocus** | | `false` | Auto focus the search input when mounted |
| **color** | | `#ae65c5` | The top bar anchors select and hover color |
| **emoji** | | `department_store` | The emoji shown when no emojis are hovered |
| **include** | | `['People', 'Flags']` | Only load included categories |
Expand Down
7 changes: 5 additions & 2 deletions src/components/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export default class Picker extends React.Component {
}

render() {
var { perLine, emojiSize, set, sheetSize, style, title, emoji, color, native, backgroundImageFn, emojisToShowFilter } = this.props,
var { perLine, emojiSize, set, sheetSize, style, title, emoji, color, native, backgroundImageFn, emojisToShowFilter, autoFocus } = this.props,
{ skin } = this.state,
width = (perLine * (emojiSize + 12)) + 12 + 2

Expand All @@ -286,6 +286,7 @@ export default class Picker extends React.Component {
onSearch={this.handleSearch.bind(this)}
i18n={this.i18n}
emojisToShowFilter={emojisToShowFilter}
autoFocus={autoFocus}
/>

{this.getCategories().map((category, i) => {
Expand Down Expand Up @@ -353,7 +354,8 @@ Picker.propTypes = {
sheetSize: Emoji.propTypes.sheetSize,
emojisToShowFilter: React.PropTypes.func,
include: React.PropTypes.arrayOf(React.PropTypes.string),
exclude: React.PropTypes.arrayOf(React.PropTypes.string)
exclude: React.PropTypes.arrayOf(React.PropTypes.string),
autoFocus: React.PropTypes.bool,
}

Picker.defaultProps = {
Expand All @@ -371,4 +373,5 @@ Picker.defaultProps = {
sheetSize: Emoji.defaultProps.sheetSize,
backgroundImageFn: Emoji.defaultProps.backgroundImageFn,
emojisToShowFilter: (codePoint) => true,
autoFocus: false,
}
9 changes: 6 additions & 3 deletions src/components/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,29 @@ export default class Search extends React.Component {
}

render() {
var { i18n } = this.props
var { i18n, autoFocus } = this.props

return <input
ref='input'
type='text'
onChange={this.handleChange.bind(this)}
placeholder={i18n.search}
className='emoji-mart-search'
autoFocus={autoFocus}
/>
}
}

Search.propTypes = {
onSearch: React.PropTypes.func,
maxResults: React.PropTypes.number,
emojisToShowFilter: React.PropTypes.func
emojisToShowFilter: React.PropTypes.func,
autoFocus: React.PropTypes.bool,
}

Search.defaultProps = {
onSearch: (() => {}),
maxResults: 75,
emojisToShowFilter: () => true
emojisToShowFilter: () => true,
autoFocus: false,
}

0 comments on commit 3c78aee

Please sign in to comment.