Skip to content

Commit

Permalink
Add support for radio names (#348)
Browse files Browse the repository at this point in the history
* Add support for radio names

* Add PR link
  • Loading branch information
zinckiwi authored Jan 30, 2018
1 parent 5a7c352 commit bf1fe70
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# [`master`](https://github.com/elastic/eui/tree/master)

- `EuiRadio` now supports the `input` tag's `name` attribute. `EuiRadioGroup` accepts a `name` prop that will propagate to its `EuiRadio`s. ([#348](https://github.com/elastic/eui/pull/348))
- Machine learning create jobs icon set. ([#338](https://github.com/elastic/eui/pull/338))
- Initial commit of `EuiTableOfRecords` - a higher level table component to take away all your table listings frustrations. ([#250](https://github.com/elastic/eui/pull/250))

Expand Down
51 changes: 51 additions & 0 deletions src/components/form/radio/__snapshots__/radio_group.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,57 @@ exports[`EuiRadioGroup props idSelected is rendered 1`] = `
</div>
`;

exports[`EuiRadioGroup props name is propagated to radios 1`] = `
<div>
<div
class="euiRadio euiRadioGroup__item"
>
<input
class="euiRadio__input"
id="1"
name="radiogroupname"
type="radio"
/>
<div
class="euiRadio__circle"
>
<div
class="euiRadio__check"
/>
</div>
<label
class="euiRadio__label"
for="1"
>
Option #1
</label>
</div>
<div
class="euiRadio euiRadioGroup__item"
>
<input
class="euiRadio__input"
id="2"
name="radiogroupname"
type="radio"
/>
<div
class="euiRadio__circle"
>
<div
class="euiRadio__check"
/>
</div>
<label
class="euiRadio__label"
for="2"
>
Option #2
</label>
</div>
</div>
`;

exports[`EuiRadioGroup props options are rendered 1`] = `
<div>
<div
Expand Down
2 changes: 2 additions & 0 deletions src/components/form/radio/radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import classNames from 'classnames';
export const EuiRadio = ({
className,
id,
name,
checked,
label,
onChange,
Expand Down Expand Up @@ -38,6 +39,7 @@ export const EuiRadio = ({
className="euiRadio__input"
type="radio"
id={id}
name={name}
checked={checked}
onChange={onChange}
disabled={disabled}
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 @@ -7,6 +7,7 @@ export const EuiRadioGroup = ({
options,
idSelected,
onChange,
name,
className,
disabled,
...rest
Expand All @@ -18,6 +19,7 @@ export const EuiRadioGroup = ({
className="euiRadioGroup__item"
key={index}
id={option.id}
name={name}
checked={option.id === idSelected}
label={option.label}
disabled={disabled}
Expand Down
16 changes: 16 additions & 0 deletions src/components/form/radio/radio_group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ describe('EuiRadioGroup', () => {
.toMatchSnapshot();
});

test('name is propagated to radios', () => {
const component = render(
<EuiRadioGroup
name="radiogroupname"
options={[
{ id: '1', label: 'Option #1' },
{ id: '2', label: 'Option #2' }
]}
onChange={() => {}}
/>
);

expect(component)
.toMatchSnapshot();
});

test('idSelected is rendered', () => {
const component = render(
<EuiRadioGroup
Expand Down

0 comments on commit bf1fe70

Please sign in to comment.