diff --git a/CHANGELOG.md b/CHANGELOG.md index 44068ddb3e7..daba6ec9059 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ - Fixed `EuiContextMenuPanel` calling `ref` after being unmounted ([#1038](https://github.com/elastic/eui/pull/1038)) +**Bug Fixes** + +- To make it more accessible, added a random id to `EuiSwitch`'s id prop if none is passed. ([#779](https://github.com/elastic/eui/pull/779)) + + ## [`3.1.0`](https://github.com/elastic/eui/tree/v3.1.0) - Added `EuiMutationObserver` to expose Mutation Observer API to React components ([#966](https://github.com/elastic/eui/pull/966)) diff --git a/src-docs/src/views/form_controls/switch.js b/src-docs/src/views/form_controls/switch.js index d250b06769a..8ccd52a2030 100644 --- a/src-docs/src/views/form_controls/switch.js +++ b/src-docs/src/views/form_controls/switch.js @@ -8,8 +8,6 @@ import { EuiSpacer, } from '../../../../src/components'; -import makeId from '../../../../src/components/form/form_row/make_id'; - export default class extends Component { constructor(props) { super(props); @@ -29,7 +27,6 @@ export default class extends Component { return ( { - const classes = classNames( - 'euiSwitch', - { - 'euiSwitch--compressed': compressed, - }, - className - ); +export class EuiSwitch extends Component { + constructor(props) { + super(props); - return ( -
- + this.state = { + id: props.id || makeId(), + }; + } - - - - + render() { + const { + label, + id, + name, + checked, + disabled, + compressed, + onChange, + className, + ...rest + } = this.props; - - - + const { switchId } = this.state; - { label && - - } + const classes = classNames( + 'euiSwitch', + { + 'euiSwitch--compressed': compressed, + }, + className + ); -
- ); -}; + return ( +
+ + + + + + + + + + + + { label && + + } +
+ ); + } +} EuiSwitch.propTypes = { name: PropTypes.string, diff --git a/src/components/form/switch/switch.test.js b/src/components/form/switch/switch.test.js index 7d4798b258f..2d916946266 100644 --- a/src/components/form/switch/switch.test.js +++ b/src/components/form/switch/switch.test.js @@ -7,7 +7,7 @@ import { EuiSwitch } from './switch'; describe('EuiSwitch', () => { test('is rendered', () => { const component = render( - + ); expect(component)