From e2b98b3dece04135934ddb7fedf830c07a6c97c7 Mon Sep 17 00:00:00 2001 From: Caroline Horn <549577+cchaos@users.noreply.github.com> Date: Wed, 16 Jan 2019 15:01:54 -0500 Subject: [PATCH] Button group fixes (#1444) --- CHANGELOG.md | 5 +- src-docs/src/views/button/button_example.js | 7 ++ src-docs/src/views/button/button_group.js | 17 ++-- .../__snapshots__/button_group.test.js.snap | 12 +-- .../button/button_group/button_group.js | 83 +++++++++++-------- src/components/form/switch/_mixins.scss | 3 +- src/global_styling/reset/_reset.scss | 4 + 7 files changed, 86 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b91b44078b1..44e7729d4fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## [`master`](https://github.com/elastic/eui/tree/master) -No public interface changes since `6.4.0`. +**Bug fixes** + +- Added `legend` for accessibility of `EuiButtonGroup` and fixed opacity of disabled input ([#1444](https://github.com/elastic/eui/pull/1444)) + ## [`6.4.0`](https://github.com/elastic/eui/tree/v6.4.0) diff --git a/src-docs/src/views/button/button_example.js b/src-docs/src/views/button/button_example.js index c2d5f78374d..678c8bb9cd0 100644 --- a/src-docs/src/views/button/button_example.js +++ b/src-docs/src/views/button/button_example.js @@ -15,6 +15,7 @@ import { EuiCode, EuiButtonGroup, EuiButtonToggle, + EuiCallOut, } from '../../../../src/components'; import Button from './button'; @@ -251,6 +252,12 @@ export const ButtonExample = { (default) or "primary". If your just displaying a group of icons, add the prop isIconOnly.

+ +

+ In order for groups to be properly read as groups with a title, add the legend prop. + This is only for accessiblity, however, so it will be visibly hidden. +

+
), demo: , diff --git a/src-docs/src/views/button/button_group.js b/src-docs/src/views/button/button_group.js index f1f349d0179..1138751fb77 100644 --- a/src-docs/src/views/button/button_group.js +++ b/src-docs/src/views/button/button_group.js @@ -58,18 +58,22 @@ export default class extends Component { this.toggleButtonsIconsMulti = [{ id: `${idPrefix3}3`, label: 'Bold', + name: 'bold', iconType: 'editorBold', }, { id: `${idPrefix3}4`, label: 'Italic', + name: 'italic', iconType: 'editorItalic', }, { id: `${idPrefix3}5`, label: 'Underline', + name: 'underline', iconType: 'editorUnderline', }, { id: `${idPrefix3}6`, label: 'Strikethrough', + name: 'strikethrough', iconType: 'editorStrike', }]; @@ -119,7 +123,7 @@ export default class extends Component { return ( +
+
+
`; diff --git a/src/components/button/button_group/button_group.js b/src/components/button/button_group/button_group.js index da8f0632c20..326e09c772a 100644 --- a/src/components/button/button_group/button_group.js +++ b/src/components/button/button_group/button_group.js @@ -2,6 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; +import { EuiScreenReaderOnly } from '../../accessibility'; import { EuiButtonToggle } from '../button_toggle'; import { TOGGLE_TYPES } from '../../toggle'; @@ -15,6 +16,7 @@ export const EuiButtonGroup = ({ isFullWidth, isIconOnly, name, + legend, onChange, options, type, @@ -29,40 +31,50 @@ export const EuiButtonGroup = ({ className, ); + let legendNode; + if (legend) { + legendNode = ( + {legend} + ); + } + return ( -
- {options.map((option, index) => { - - let isSelectedState; - if (type === 'multi') { - isSelectedState = idToSelectedMap[option.id] || false; - } else { - isSelectedState = option.id === idSelected; - } - - return ( - - ); - })} -
+
+ {legendNode} + +
+ {options.map((option, index) => { + let isSelectedState; + if (type === 'multi') { + isSelectedState = idToSelectedMap[option.id] || false; + } else { + isSelectedState = option.id === idSelected; + } + + return ( + + ); + })} +
+
); }; @@ -112,6 +124,11 @@ EuiButtonGroup.propTypes = { * Map of ids of selected options for `type="multi"` */ idToSelectedMap: PropTypes.objectOf(PropTypes.bool), + + /** + * Adds a hidden legend to the group for accessiblity + */ + legend: PropTypes.string, }; EuiButtonGroup.defaultProps = { diff --git a/src/components/form/switch/_mixins.scss b/src/components/form/switch/_mixins.scss index 7d952267648..743d915644f 100644 --- a/src/components/form/switch/_mixins.scss +++ b/src/components/form/switch/_mixins.scss @@ -1,6 +1,7 @@ @mixin euiHiddenSelectableInput { position: absolute; - opacity: 0; /* 1 */ + // sass-lint:disable no-important + opacity: 0 !important; // Make sure it's still hidden when :disabled width: 100%; height: 100%; cursor: pointer; diff --git a/src/global_styling/reset/_reset.scss b/src/global_styling/reset/_reset.scss index 0cfd6517ee5..3146a2db2f3 100644 --- a/src/global_styling/reset/_reset.scss +++ b/src/global_styling/reset/_reset.scss @@ -133,3 +133,7 @@ table { hr { margin: 0; } + +fieldset { + min-inline-size: auto; +}