Skip to content

Commit

Permalink
set default params on load, change value select handling (#270)
Browse files Browse the repository at this point in the history
* set default params on load, change value select handling

* add changelog to pr
  • Loading branch information
avrilpearl authored and clairesunstudio committed Sep 26, 2018
1 parent 53b745d commit 172125e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelogs/DP-10497.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
___DESCRIPTION___
Fixed/Changed
Impact: Minor
- React DP-10497: Updates the selectbox atom in Mayflower-React, passing the default selected prop to state in the contructor. Also updates the setting of select in the selectbox, changing for ref to value.
8 changes: 4 additions & 4 deletions react/src/components/atoms/forms/SelectBox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ class SelectBox extends React.Component {
constructor(props) {
super(props);
this.state = {
selected: props.options[0].text
selected: !props.selected ? props.options[0].text : props.selected
};
this.selectTag = '';
this.handleOnChange = this.handleOnChange.bind(this);
}
componentWillReceiveProps(nextProps) {
this.setState({ selected: nextProps.selected });
this.selectTag.selectedIndex = nextProps.options.findIndex((option) => option.text === nextProps.selected);
}
/**
* Default event handler which renders selected item in the patter div.
Expand Down Expand Up @@ -47,6 +45,8 @@ class SelectBox extends React.Component {
const { stackLabel } = this.props;
const labelClassNames = stackLabel ? 'ma__select-box__label' : 'ma__label--inline ma__label--small';
const selectBoxInline = stackLabel ? '' : 'ma__select-box__field--inline';
const selectedIndex = this.props.options.findIndex((option) => option.text === selected);

return(
<section className={classNames}>
<label htmlFor={this.props.id} className={labelClassNames}>{this.props.label}</label>
Expand All @@ -57,7 +57,7 @@ class SelectBox extends React.Component {
id={this.props.id}
className={selectClassNames}
onChange={this.handleOnChange}
ref={(select) => { this.selectTag = select; }}
value={(this.props.options[selectedIndex]).value}
>
{this.props.options.map((option) => (
<option key={option.value} value={option.value}>
Expand Down

0 comments on commit 172125e

Please sign in to comment.