-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow disabling of EuiSelect options #324
Allow disabling of EuiSelect options #324
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had an idea, what do you think?
src/components/form/select/select.js
Outdated
if (option.disabled) { | ||
props.disabled = true; | ||
} | ||
return <option {...props}>{option.text}</option>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using ...rest
to support basic HTML attributes like disabled
, value
, etc?
{options.map((option, index) => {
const {
text,
...rest
} = option;
return <option {...rest} key={index}>{text}</option>;
})}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I like it
src/components/form/select/select.js
Outdated
@@ -60,6 +67,7 @@ EuiSelect.propTypes = { | |||
options: PropTypes.arrayOf(PropTypes.shape({ | |||
value: PropTypes.string.isRequired, | |||
text: PropTypes.string.isRequired, | |||
disabled: PropTypes.bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can then remove value
and disabled
from this propType definition since they're just being passed-through.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…ptions-disabled-support # Conflicts: # CHANGELOG.md
@zinckiwi you mind rebasing and merging when you have a moment. |
Added a formal property in
EuiSelect
'soptions
prop ofdisabled
, propagated to the<option>
when truthy.