Skip to content

Commit

Permalink
Merge pull request #26 from ship-components/bugfix/select-errors
Browse files Browse the repository at this point in the history
Fixed invalid options in select tag and improved option rendering logic
  • Loading branch information
adamsas committed Nov 26, 2019
2 parents 9e14053 + 66219c4 commit 64b4c53
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 51 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Below are is a sample of how to setup the loaders:

## History

* 1.1.7 - Fixed invalid options in select tag and improved option rendering logic
* 1.1.6 - Fixed a bug with dispatching events in IE11, deprecated Node 6
* 1.1.5 - Fixed a calc bug from the lastest postcss
* 1.1.4 - Updated dependencies (for security)
Expand Down
43 changes: 12 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ship-components-select",
"version": "1.1.6",
"version": "1.1.7",
"description": "Material Design React Select Box",
"main": "src/Select.js",
"scripts": {
Expand Down
14 changes: 7 additions & 7 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,26 +306,26 @@ export default class Select extends React.Component {
{(this.state.active ? opts : []).map(option => (
<SelectOption
{...option}
tag='li'
key={option.key || option.value}
ref={option.value === currentValue.value ? 'selected' : void 0}
selected={option.value === currentValue.value}
onClick={this.handleClickItem.bind(this, option.value)} //eslint-disable-line
key={option.key || option.value}
/>
))}
</ul>
<select
ref='input'
readOnly
value={this.props.value}
value={currentValue.value}
style={{display : 'none'}}
>
{opts.map(option => (
<SelectOption
{...option}
selected={option.value === currentValue.value}
<option
key={option.key || option.value}
/>
value={option.value}
>
{option.label || option.value}
</option>
))}
</select>
</OutsideClick>
Expand Down
23 changes: 11 additions & 12 deletions src/SelectOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@ import classNames from 'classnames';
import cssClassNames from './select.css';

/**
* If we have a render option use that if we're not an <option>. Options only
* support strings and numbers
* Render option content
* @return {React}
*/
function getContents(props) {
if (props.tag !== 'option' && props.render) {
return props.render;
} else {
return props.label || props.value;
}
return props.render || props.label || props.value;
}

export default class SelectOption extends React.Component {

shouldComponentUpdate(nextProps) {
if (nextProps.tag !== 'option' && nextProps.render) { // eslint-disable-line react/prop-types
if (nextProps.render) {
// Rendering a another component so we just skip
return true;
}
Expand All @@ -45,30 +40,34 @@ export default class SelectOption extends React.Component {
}
);
return (
<this.props.tag
<li
className={classes}
value={this.props.value}
onClick={this.props.onClick}
>
{getContents(this.props)}
</this.props.tag>
</li>
);
}
}

SelectOption.defaultProps = {
className: '',
label: '',
tag: 'option',
render: void 0,
selected: false,
onClick: void 0
};

SelectOption.propTypes = {
className: PropTypes.string,
label: PropTypes.string,
render: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
PropTypes.string
]),
value: PropTypes.string.isRequired,
tag: PropTypes.string,
onClick: PropTypes.func,
selected: PropTypes.bool
};

0 comments on commit 64b4c53

Please sign in to comment.