Skip to content

Commit

Permalink
[EuiRadio] Make id required if label is present (#3382)
Browse files Browse the repository at this point in the history
* id is required if lable is passed

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update radio.tsx

* Update CHANGELOG.md

Co-Authored-By: Greg Thompson <[email protected]>

* removed as EuiRadioProps

Co-authored-by: Greg Thompson <[email protected]>
  • Loading branch information
anishagg17 and thompsongl authored Apr 27, 2020
1 parent 43f0cf6 commit 4582b32
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

**Bug Fixes**

- Added `id` requirement if `label` is used in `EuiRadio` ([#3382](https://github.com/elastic/eui/pull/3382))
- Fixed z-index issue in `EuiDatePicker` where it's popover would sit beneath other DOM siblings that had z-index applied ([#3376](https://github.com/elastic/eui/pull/3376))
- Added `download` glyph to `EuiIcon` ([#3364](https://github.com/elastic/eui/pull/3364))
- Applies `max-width: 100%` to `EuiPageBody` so inner flex-based items don't overflow their containers ([#3375](https://github.com/elastic/eui/pull/3375))
Expand Down
19 changes: 13 additions & 6 deletions src/components/form/radio/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,33 @@ import React, {
ReactNode,
} from 'react';
import classNames from 'classnames';
import { CommonProps } from '../../common';
import { CommonProps, ExclusiveUnion } from '../../common';

export interface RadioProps {
autoFocus?: boolean;
/**
* When `true` creates a shorter height radio row
*/
compressed?: boolean;
label?: ReactNode;
name?: string;
value?: string;
checked?: boolean;
disabled?: boolean;
onChange: ChangeEventHandler<HTMLInputElement>;
}

export interface EuiRadioProps
extends CommonProps,
Omit<HTMLAttributes<HTMLDivElement>, 'onChange'>,
RadioProps {}
interface idWithLabel extends RadioProps {
label: ReactNode;
id: string;
}

interface withId extends RadioProps {
id: string;
}

export type EuiRadioProps = CommonProps &
Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> &
ExclusiveUnion<ExclusiveUnion<RadioProps, idWithLabel>, withId>;

export const EuiRadio: FunctionComponent<EuiRadioProps> = ({
className,
Expand Down
8 changes: 6 additions & 2 deletions src/components/form/radio/radio_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,21 @@ export const EuiRadioGroup: FunctionComponent<EuiRadioGroupProps> = ({
const {
disabled: isOptionDisabled,
className: optionClass,
id,
label,
...optionRest
} = option;
return (
<EuiRadio
className={classNames('euiRadioGroup__item', optionClass)}
key={index}
name={name}
checked={option.id === idSelected}
checked={id === idSelected}
disabled={disabled || isOptionDisabled}
onChange={onChange.bind(null, option.id, option.value)}
onChange={onChange.bind(null, id, option.value)}
compressed={compressed}
id={id}
label={label}
{...optionRest}
/>
);
Expand Down

0 comments on commit 4582b32

Please sign in to comment.