Skip to content

Commit

Permalink
Use data-value attribute instead of value for an <li/>, when firing o…
Browse files Browse the repository at this point in the history
…nChange call with the event followed by the value instead of mutating the target

Signed-off-by: Ryan Dy <rdy@pivotal.io>
  • Loading branch information
Jeanette Booher authored and rdy committed Oct 17, 2017
1 parent 66e8b92 commit 16b48b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion spec/pivotal-ui-react/select/select_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('Select', () => {

it('calls then onChange callback', () => {
//cannot assert on event object due to phantomJS limitation
expect(onChangeSpy).toHaveBeenCalledWith(jasmine.any(Object));
expect(onChangeSpy).toHaveBeenCalledWith(jasmine.any(Object), 'one');
});

it('updates the selected value', () => {
Expand Down
7 changes: 3 additions & 4 deletions src/react/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ export class Select extends mixin(React.Component).with(Scrim, Transition) {
toggle = () => this.setState({open: !this.state.open});

select = e => {
const value = e.target.getAttribute('value');
Object.defineProperty(e.target, 'value', {value});
const value = e.target.getAttribute('data-value');

this.setState({
open: false,
uncontrolledValue: value
}, this.props.onChange && this.props.onChange(e));
}, this.props.onChange && this.props.onChange(e, value));
};

scrimClick = () => this.setState({open: false});
Expand All @@ -63,7 +62,7 @@ export class Select extends mixin(React.Component).with(Scrim, Transition) {
className,
key: value,
role: 'button',
value,
'data-value': value,
onClick: this.select
}}>{label}</li>);
return memo;
Expand Down

0 comments on commit 16b48b9

Please sign in to comment.