Skip to content

Commit

Permalink
fix: Fix onFocus and onBlur to work with redux-form
Browse files Browse the repository at this point in the history
  • Loading branch information
HriBB committed Aug 21, 2016
1 parent e2f6137 commit 4bc286b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "es/index.js",
"jsnext:main": "es/index.js",
"scripts": {
"clean": "rimraf lib dist es",
"start": "npm run storybook",
"storybook": "cross-env NODE_ENV=development start-storybook -p 9002",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib && cp src/SelectField/SelectField.scss lib/SelectField/SelectField.scss && cp src/MultiSelectField/MultiSelectField.scss lib/MultiSelectField/MultiSelectField.scss",
Expand All @@ -15,7 +16,7 @@
"build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
"lint": "eslint src/** test/**",
"gh-pages": "gh-pages-deploy",
"prepublish": "npm run lint && npm build",
"prepublish": "npm run clean && npm run build",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"test": "mocha --require test/config/setup 'test/*.js'",
"test:cover": "istanbul cover -x *.test.js _mocha -- -R spec --require test/config/setup 'test/*.js'"
Expand Down
18 changes: 13 additions & 5 deletions src/MultiSelectField/MultiSelectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default class MultiSelectField extends Component {
value: [],
}


constructor(props) {
super(props)

Expand All @@ -39,6 +38,8 @@ export default class MultiSelectField extends Component {
tags: [],
}

this.onSelectFocus = this.onSelectFocus.bind(this)
this.onSelectBlur = this.onSelectBlur.bind(this)
this.onSelectChange = this.onSelectChange.bind(this)
this.onTagClick = this.onTagClick.bind(this)
}
Expand All @@ -59,6 +60,14 @@ export default class MultiSelectField extends Component {
}
}

onSelectFocus() {
if (this.props.onFocus) this.props.onFocus(this.state.value)
}

onSelectBlur() {
if (this.props.onBlur) this.props.onBlur(this.state.value)
}

onSelectChange(val, text) {
const { value, tags } = this.state
if (value.indexOf(val) === -1) {
Expand All @@ -83,8 +92,7 @@ export default class MultiSelectField extends Component {

render() {
const {
floatingLabel, className, label, readOnly, editable,
error, onFocus, onBlur, children,
floatingLabel, className, label, readOnly, editable, error, children,
} = this.props
const { value, tags } = this.state
const mainClass = classnames('mdl-multiselectfield', className)
Expand All @@ -99,8 +107,8 @@ export default class MultiSelectField extends Component {
editable={editable}
readOnly={readOnly}
skipValues={value}
onFocus={onFocus}
onBlur={onBlur}
onFocus={this.onSelectFocus}
onBlur={this.onSelectBlur}
onChange={this.onSelectChange}
>
{children}
Expand Down
8 changes: 4 additions & 4 deletions src/SelectField/SelectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ export default class SelectField extends Component {
this.hideMenu()
}

onTextfieldFocus(e) {
onTextfieldFocus() {
this.showMenu()
this.setState({ focused: true })
if (this.props.onFocus) this.props.onFocus(e)
if (this.props.onFocus) this.props.onFocus(this.state.value)
}

onTextfieldBlur(e) {
onTextfieldBlur() {
this.setState({ focused: false })
if (this.props.onBlur) this.props.onBlur(e)
if (this.props.onBlur) this.props.onBlur(this.state.value)
}

onTextfieldChange(e) {
Expand Down

0 comments on commit 4bc286b

Please sign in to comment.