Skip to content
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 setting autoFocus on radio group option #1117

Merged
merged 4 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/form/radio/radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const EuiRadio = ({
onChange,
disabled,
compressed,
autoFocus,
...rest
}) => {
const classes = classNames(
Expand Down Expand Up @@ -50,6 +51,7 @@ export const EuiRadio = ({
checked={checked}
onChange={onChange}
disabled={disabled}
autoFocus={autoFocus}
/>

<div className="euiRadio__circle" />
Expand All @@ -71,6 +73,7 @@ EuiRadio.propTypes = {
* when `true` creates a shorter height radio row
*/
compressed: PropTypes.bool,
autoFocus: PropTypes.bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think you still don't need these? autofocus is html prop. Unless React expects it to be passed as a camel case prop autoFocus?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not work unless camel cased

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it

};

EuiRadio.defaultProps = {
Expand Down
2 changes: 2 additions & 0 deletions src/components/form/radio/radio_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const EuiRadioGroup = ({
disabled={disabled || option.disabled}
onChange={onChange.bind(null, option.id, option.value)}
compressed={compressed}
autoFocus={option.autofocus}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just need to add a ...rest for options like we have started doing for most components that accept options as objects:

    const items = options.map((option, index) => {
      const {
        [props]
        ...optionRest
      } = option;

      return (
        <EuiRadio
          [props]
          { ...optionRest }
        />
      );
    });

/>
);
})}
Expand All @@ -40,6 +41,7 @@ EuiRadioGroup.propTypes = {
label: PropTypes.node,
value: PropTypes.string,
disabled: PropTypes.bool,
autoFocus: PropTypes.bool,
}),
).isRequired,
idSelected: PropTypes.string,
Expand Down