From 7a153dc2da8545af48bd67f5dfc4592fcb01b901 Mon Sep 17 00:00:00 2001 From: NightWing1998 Date: Fri, 20 Mar 2020 00:13:12 +0530 Subject: [PATCH 01/10] shifting makeId to htmlIdGenerator --- src-docs/src/views/form_layouts/form_rows.js | 5 +++-- src/components/form/form_row/form_row.tsx | 10 ++++++---- src/components/form/form_row/make_id.ts | 3 +++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src-docs/src/views/form_layouts/form_rows.js b/src-docs/src/views/form_layouts/form_rows.js index c47cf321f6c..d5188437aeb 100644 --- a/src-docs/src/views/form_layouts/form_rows.js +++ b/src-docs/src/views/form_layouts/form_rows.js @@ -15,13 +15,14 @@ import { EuiText, } from '../../../../src/components'; -import makeId from '../../../../src/components/form/form_row/make_id'; +// import makeId from '../../../../src/components/form/form_row/make_id'; +import { htmlIdGenerator } from '../../../../src/services/accessibility'; export default class extends Component { constructor(props) { super(props); - const idPrefix = makeId(); + const idPrefix = htmlIdGenerator()(); this.state = { isSwitchChecked: false, diff --git a/src/components/form/form_row/form_row.tsx b/src/components/form/form_row/form_row.tsx index 472b25b4ac6..98840422ceb 100644 --- a/src/components/form/form_row/form_row.tsx +++ b/src/components/form/form_row/form_row.tsx @@ -15,7 +15,9 @@ import { EuiFormHelpText } from '../form_help_text'; import { EuiFormErrorText } from '../form_error_text'; import { EuiFormLabel } from '../form_label'; -import makeId from './make_id'; +// import makeId from './make_id'; + +import { htmlIdGenerator } from '../../../services/accessibility'; const displayToClassNameMap = { row: null, @@ -110,7 +112,7 @@ export class EuiFormRow extends Component { state: EuiFormRowState = { isFocused: false, - id: this.props.id || makeId(), + id: this.props.id || htmlIdGenerator()(), }; onFocus = (...args: any[]) => { @@ -302,11 +304,11 @@ export class EuiFormRow extends Component { return labelType === 'legend' ? (
}> + {...(rest as HTMLAttributes)}> {contents}
) : ( -
}> +
)}> {contents}
); diff --git a/src/components/form/form_row/make_id.ts b/src/components/form/form_row/make_id.ts index 765e69939e5..71db07f5f4c 100644 --- a/src/components/form/form_row/make_id.ts +++ b/src/components/form/form_row/make_id.ts @@ -1,6 +1,9 @@ // Generate statistically almost-certainly-unique `id`s for associating form // inputs with their labels and other descriptive text elements. function makeId(): string { + console.log( + 'WARNING: makeId is deprecated. Use htmlIdGenerator from services instead.' + ); return Math.random() .toString(36) .slice(-8); From 921698848babbb92bd308eb1c56b95a8683a2228 Mon Sep 17 00:00:00 2001 From: NightWing1998 Date: Fri, 20 Mar 2020 12:40:37 +0530 Subject: [PATCH 02/10] shifted from makeId to htmlIdgenerator --- src-docs/src/views/button/button_group.js | 287 +++++++++++------- src-docs/src/views/card/card_checkable.js | 12 +- .../views/form_compressed/complex_example.js | 8 +- .../views/form_compressed/form_compressed.js | 4 +- src-docs/src/views/form_controls/checkbox.js | 10 +- .../src/views/form_controls/checkbox_group.js | 4 +- src-docs/src/views/form_controls/radio.js | 8 +- .../src/views/form_controls/radio_group.js | 4 +- .../form_layouts/described_form_group.js | 4 +- src-docs/src/views/form_layouts/form_rows.js | 1 - .../src/views/form_layouts/inline_popover.js | 4 +- src-docs/src/views/guidelines/writing.js | 6 +- src-docs/src/views/modal/modal.js | 4 +- src-docs/src/views/range/dual_range.js | 4 +- src-docs/src/views/range/input.js | 6 +- src-docs/src/views/range/input_only.js | 6 +- src-docs/src/views/range/levels.js | 6 +- src-docs/src/views/range/range.js | 8 +- src-docs/src/views/range/states.js | 6 +- src-docs/src/views/range/ticks.js | 8 +- src-docs/src/views/suggest/suggest.js | 4 +- src-docs/src/views/tables/auto/auto.js | 4 +- src/components/basic_table/basic_table.tsx | 5 +- src/components/card/card.test.tsx | 5 +- src/components/card/card.tsx | 4 +- .../combo_box_input/combo_box_input.tsx | 4 +- .../described_form_group.test.tsx | 4 +- .../form/form_row/form_row.test.tsx | 4 +- src/components/form/form_row/form_row.tsx | 6 +- src/components/form/range/dual_range.test.tsx | 4 +- src/components/form/range/dual_range.tsx | 5 +- src/components/form/range/range.test.tsx | 4 +- src/components/form/range/range.tsx | 4 +- .../__snapshots__/super_select.test.tsx.snap | 16 +- .../form/super_select/super_select.test.tsx | 14 +- .../super_select_control.test.tsx | 4 +- .../super_select/super_select_control.tsx | 4 +- src/components/form/switch/switch.test.tsx | 4 +- src/components/form/switch/switch.tsx | 6 +- .../header/header_alert/header_alert.test.tsx | 4 +- .../header/header_alert/header_alert.tsx | 4 +- .../tabs/tabbed_content/tabbed_content.tsx | 4 +- src/components/tool_tip/tool_tip.test.tsx | 4 + src/components/tool_tip/tool_tip.tsx | 5 +- 44 files changed, 303 insertions(+), 223 deletions(-) diff --git a/src-docs/src/views/button/button_group.js b/src-docs/src/views/button/button_group.js index 97978761e66..ccccf9013e7 100644 --- a/src-docs/src/views/button/button_group.js +++ b/src-docs/src/views/button/button_group.js @@ -1,4 +1,7 @@ -import React, { Component, Fragment } from 'react'; +import React, { + Component, + Fragment +} from 'react'; import { EuiButtonGroup, @@ -6,19 +9,22 @@ import { EuiTitle, } from '../../../../src/components'; -import makeId from '../../../../src/components/form/form_row/make_id'; -import { EuiPanel } from '../../../../src/components/panel/panel'; +import { + htmlIdGenerator +} from "../../../../src/services"; +import { + EuiPanel +} from '../../../../src/components/panel/panel'; export default class extends Component { constructor(props) { super(props); - const idPrefix = makeId(); - const idPrefix2 = makeId(); - const idPrefix3 = makeId(); + const idPrefix = htmlIdGenerator()(); + const idPrefix2 = htmlIdGenerator()(); + const idPrefix3 = htmlIdGenerator()(); - this.toggleButtons = [ - { + this.toggleButtons = [{ id: `${idPrefix}0`, label: 'Option one', }, @@ -32,8 +38,7 @@ export default class extends Component { }, ]; - this.toggleButtonsDisabled = [ - { + this.toggleButtonsDisabled = [{ id: `${idPrefix}3`, label: 'Option one', }, @@ -47,8 +52,7 @@ export default class extends Component { }, ]; - this.toggleButtonsMulti = [ - { + this.toggleButtonsMulti = [{ id: `${idPrefix2}0`, label: 'Option 1', }, @@ -62,8 +66,7 @@ export default class extends Component { }, ]; - this.toggleButtonsCompressed = [ - { + this.toggleButtonsCompressed = [{ id: `${idPrefix2}3`, label: 'fine', }, @@ -77,8 +80,7 @@ export default class extends Component { }, ]; - this.toggleButtonsIcons = [ - { + this.toggleButtonsIcons = [{ id: `${idPrefix3}0`, label: 'Align left', iconType: 'editorAlignLeft', @@ -95,8 +97,7 @@ export default class extends Component { }, ]; - this.toggleButtonsIconsMulti = [ - { + this.toggleButtonsIconsMulti = [{ id: `${idPrefix3}3`, label: 'Bold', name: 'bold', @@ -199,101 +200,161 @@ export default class extends Component { }; render() { - return ( - - - - -

Primary & multi select

-
- - - - -

Disabled & full width

-
- - - - -

Icons only

-
- - -    - - - - -

- Compressed groups should always be fullWidth so they line up - nicely in their small container. -

-
- - - - -

Unless they are icon only

-
- - -
-
+ return ( < + Fragment > + < + EuiButtonGroup legend = "This is a basic group" + options = { + this.toggleButtons + } + idSelected = { + this.state.toggleIdSelected + } + onChange = { + this.onChange + } + /> < + EuiSpacer size = "m" / > + < + EuiTitle size = "xxs" > + < + h3 > Primary & amp; multi select < /h3> < / + EuiTitle > < + EuiSpacer size = "s" / > + < + EuiButtonGroup legend = "This is a primary group" + name = "primary" + options = { + this.toggleButtonsMulti + } + idToSelectedMap = { + this.state.toggleIdToSelectedMap + } + onChange = { + this.onChangeMulti + } + color = "primary" + type = "multi" / + > + < + EuiSpacer size = "m" / > + < + EuiTitle size = "xxs" > + < + h3 > Disabled & amp; full width < /h3> < / + EuiTitle > < + EuiSpacer size = "s" / > + < + EuiButtonGroup legend = "This is a disabled group" + name = "disabledGroup" + options = { + this.toggleButtonsDisabled + } + idSelected = { + this.state.toggleIdDisabled + } + onChange = { + this.onChangeDisabled + } + buttonSize = "m" + isDisabled isFullWidth / + > + < + EuiSpacer size = "m" / > + < + EuiTitle size = "xxs" > + < + h3 > Icons only < /h3> < / + EuiTitle > < + EuiSpacer size = "s" / > + < + EuiButtonGroup legend = "Text align" + name = "textAlign" + options = { + this.toggleButtonsIcons + } + idSelected = { + this.state.toggleIconIdSelected + } + onChange = { + this.onChangeIcons + } + isIconOnly / + > + & + nbsp; & nbsp; < + EuiButtonGroup legend = "Text style" + options = { + this.toggleButtonsIconsMulti + } + idToSelectedMap = { + this.state.toggleIconIdToSelectedMap + } + onChange = { + this.onChangeIconsMulti + } + type = "multi" + isIconOnly / + > + < + EuiSpacer / > + < + EuiPanel style = { + { + maxWidth: 300 + } + } > + < + EuiTitle size = "xxxs" > + < + h3 > + Compressed groups should always be fullWidth so they line up nicely in their small container. < + /h3> < / + EuiTitle > < + EuiSpacer size = "s" / > + < + EuiButtonGroup name = "coarsness" + legend = "This is a basic group" + options = { + this.toggleButtonsCompressed + } + idSelected = { + this.state.toggleCompressedIdSelected + } + onChange = { + this.onChangeCompressed + } + buttonSize = "compressed" + isFullWidth / + > + < + EuiSpacer / > + < + EuiTitle size = "xxxs" > + < + h3 > Unless they are icon only < /h3> < / + EuiTitle > < + EuiSpacer size = "s" / > + < + EuiButtonGroup name = "textStyleCompressed" + legend = "Text style" + className = "eui-displayInlineBlock" + options = { + this.toggleButtonsIconsMulti + } + idToSelectedMap = { + this.state.toggleIconIdToSelectedMapIcon + } + onChange = { + this.onChangeIconsMultiIcons + } + type = "multi" + buttonSize = "compressed" + isIconOnly / + > + < + /EuiPanel> < / + Fragment > ); } } diff --git a/src-docs/src/views/card/card_checkable.js b/src-docs/src/views/card/card_checkable.js index 6befa90aace..0e68270f4d8 100644 --- a/src-docs/src/views/card/card_checkable.js +++ b/src-docs/src/views/card/card_checkable.js @@ -8,11 +8,11 @@ import { EuiFormFieldset, } from '../../../../src/components'; -import makeId from '../../../../src/components/form/form_row/make_id'; +import { htmlIdGenerator } from '../../../../src/services'; export default class extends Component { state = { - radioName: makeId(), + radioName: htmlIdGenerator()(), radio: 'radio2', nestedRadio: 'nestedRadio1', checkbox: false, @@ -47,7 +47,7 @@ export default class extends Component { ), }}> { const classes = classNames(className); @@ -615,7 +615,7 @@ export default () => ( {}} - id={makeId()} + id={htmlIdGenerator()()} label="Combine values in other bucket" /> @@ -627,7 +627,7 @@ export default () => ( {}} - id={makeId()} + id={htmlIdGenerator()()} label="Combine other" /> diff --git a/src-docs/src/views/modal/modal.js b/src-docs/src/views/modal/modal.js index c7f53bb005a..00e9a04edb0 100644 --- a/src-docs/src/views/modal/modal.js +++ b/src-docs/src/views/modal/modal.js @@ -20,7 +20,7 @@ import { import SuperSelectComplexExample from '../super_select/super_select_complex'; -import makeId from '../../../../src/components/form/form_row/make_id'; +import { htmlIdGenerator } from '../../../../src/services'; export class Modal extends Component { constructor(props) { @@ -54,7 +54,7 @@ export class Modal extends Component { { }; }; -const idPrefix = makeId(); +const idPrefix = htmlIdGenerator()(); const toggleButtons = [ { diff --git a/src/components/basic_table/basic_table.tsx b/src/components/basic_table/basic_table.tsx index a7c63d33fab..7fa045c7c83 100644 --- a/src/components/basic_table/basic_table.tsx +++ b/src/components/basic_table/basic_table.tsx @@ -42,7 +42,8 @@ import { EuiIcon } from '../icon'; import { EuiKeyboardAccessible, EuiScreenReaderOnly } from '../accessibility'; import { EuiI18n } from '../i18n'; import { EuiDelayRender } from '../delay_render'; -import makeId from '../form/form_row/make_id'; + +import { htmlIdGenerator } from '../../services/accessibility'; import { Action } from './action_types'; import { EuiTableActionsColumnType, @@ -616,7 +617,7 @@ export class EuiBasicTable extends Component< {(selectAllRows: string) => ( () => 'generated-id'); +// jest.mock('./../form/form_row/make_id', () => () => 'generated-id'); +jest.mock('./../../services/accessibility', () => ({ + htmlIdGenerator: () => () => 'generated-id', +})); describe('EuiCard', () => { test('is rendered', () => { diff --git a/src/components/card/card.tsx b/src/components/card/card.tsx index f1a807d9ce5..732ff512cfe 100644 --- a/src/components/card/card.tsx +++ b/src/components/card/card.tsx @@ -12,7 +12,7 @@ import { EuiCardSelectProps, euiCardSelectableColor, } from './card_select'; -import makeId from '../form/form_row/make_id'; +import { htmlIdGenerator } from '../../services/accessibility'; type CardAlignment = 'left' | 'center' | 'right'; @@ -202,7 +202,7 @@ export const EuiCard: FunctionComponent = ({ className ); - const ariaId = makeId(); + const ariaId = htmlIdGenerator()(); /** * Top area containing image, icon or both diff --git a/src/components/combo_box/combo_box_input/combo_box_input.tsx b/src/components/combo_box/combo_box_input/combo_box_input.tsx index df31fad0183..deb17243356 100644 --- a/src/components/combo_box/combo_box_input/combo_box_input.tsx +++ b/src/components/combo_box/combo_box_input/combo_box_input.tsx @@ -23,8 +23,6 @@ import { } from '../types'; import { CommonProps } from '../../common'; -const makeId = htmlIdGenerator(); - export interface EuiComboBoxInputProps extends CommonProps { autoSizeInputRef?: RefCallback; compressed: boolean; @@ -189,7 +187,7 @@ export class EuiComboBoxInput extends Component< }Combo box input. ${readPlaceholder} Type some text or, to display a list of choices, press Down Arrow. ` + 'To exit the list of choices, press Escape.'; - removeOptionMessageId = makeId(); + removeOptionMessageId = htmlIdGenerator()(); // aria-live="assertive" will read this message aloud immediately once it enters the DOM. // We'll render to the DOM when the input gains focus and remove it when the input loses focus. diff --git a/src/components/form/described_form_group/described_form_group.test.tsx b/src/components/form/described_form_group/described_form_group.test.tsx index 0d3888edb17..de7df6a241f 100644 --- a/src/components/form/described_form_group/described_form_group.test.tsx +++ b/src/components/form/described_form_group/described_form_group.test.tsx @@ -5,7 +5,9 @@ import { requiredProps } from '../../../test'; import { EuiFormRow } from '../form_row'; import { EuiDescribedFormGroup } from './described_form_group'; -jest.mock('../form_row/make_id', () => () => 'generated-id'); +jest.mock('./../../../services/accessibility', () => ({ + htmlIdGenerator: () => () => 'generated-id', +})); describe('EuiDescribedFormGroup', () => { const props = { diff --git a/src/components/form/form_row/form_row.test.tsx b/src/components/form/form_row/form_row.test.tsx index 94edb3db718..50eea80cafc 100644 --- a/src/components/form/form_row/form_row.test.tsx +++ b/src/components/form/form_row/form_row.test.tsx @@ -4,7 +4,9 @@ import { requiredProps } from '../../../test'; import { EuiFormRow, DISPLAYS } from './form_row'; -jest.mock('./make_id', () => () => 'generated-id'); +jest.mock('./../../../services/accessibility', () => ({ + htmlIdGenerator: () => () => 'generated-id', +})); describe('EuiFormRow', () => { test('is rendered', () => { diff --git a/src/components/form/form_row/form_row.tsx b/src/components/form/form_row/form_row.tsx index 98840422ceb..c050a78fbef 100644 --- a/src/components/form/form_row/form_row.tsx +++ b/src/components/form/form_row/form_row.tsx @@ -15,8 +15,6 @@ import { EuiFormHelpText } from '../form_help_text'; import { EuiFormErrorText } from '../form_error_text'; import { EuiFormLabel } from '../form_label'; -// import makeId from './make_id'; - import { htmlIdGenerator } from '../../../services/accessibility'; const displayToClassNameMap = { @@ -304,11 +302,11 @@ export class EuiFormRow extends Component { return labelType === 'legend' ? (
)}> + {...rest as HTMLAttributes}> {contents}
) : ( -
)}> +
}> {contents}
); diff --git a/src/components/form/range/dual_range.test.tsx b/src/components/form/range/dual_range.test.tsx index 01da75f09a7..48fc073c169 100644 --- a/src/components/form/range/dual_range.test.tsx +++ b/src/components/form/range/dual_range.test.tsx @@ -4,7 +4,9 @@ import { requiredProps } from '../../../test/required_props'; import { EuiDualRange } from './dual_range'; -jest.mock('../form_row/make_id', () => () => 'generated-id'); +jest.mock('./../../../services/accessibility', () => ({ + htmlIdGenerator: () => () => 'generated-id', +})); const props = { onChange: () => {}, diff --git a/src/components/form/range/dual_range.tsx b/src/components/form/range/dual_range.tsx index 7296e7dbffb..1b05eea959f 100644 --- a/src/components/form/range/dual_range.tsx +++ b/src/components/form/range/dual_range.tsx @@ -8,7 +8,8 @@ import { EuiFormControlLayoutDelimited, EuiFormControlLayoutProps, } from '../form_control_layout'; -import makeId from '../form_row/make_id'; + +import { htmlIdGenerator } from '../../../services/accessibility'; import { EuiRangeProps } from './range'; import { EuiRangeHighlight } from './range_highlight'; @@ -102,7 +103,7 @@ export class EuiDualRange extends Component { }; state = { - id: this.props.id || makeId(), + id: this.props.id || htmlIdGenerator()(), hasFocus: false, rangeSliderRefAvailable: false, isPopoverOpen: false, diff --git a/src/components/form/range/range.test.tsx b/src/components/form/range/range.test.tsx index 2cba13f8349..d18a8aa6754 100644 --- a/src/components/form/range/range.test.tsx +++ b/src/components/form/range/range.test.tsx @@ -4,7 +4,9 @@ import { requiredProps } from '../../../test/required_props'; import { EuiRange } from './range'; -jest.mock('../form_row/make_id', () => () => 'generated-id'); +jest.mock('./../../../services/accessibility', () => ({ + htmlIdGenerator: () => () => 'generated-id', +})); const props = { value: '8', diff --git a/src/components/form/range/range.tsx b/src/components/form/range/range.tsx index 331ebd681ed..5b07f66f6f9 100644 --- a/src/components/form/range/range.tsx +++ b/src/components/form/range/range.tsx @@ -4,7 +4,7 @@ import classNames from 'classnames'; import { CommonProps } from '../../common'; import { isWithinRange } from '../../../services/number'; import { EuiInputPopover } from '../../popover'; -import makeId from '../form_row/make_id'; +import { htmlIdGenerator } from '../../../services/accessibility'; import { EuiRangeHighlight } from './range_highlight'; import { EuiRangeInput, EuiRangeInputProps } from './range_input'; @@ -93,7 +93,7 @@ export class EuiRange extends Component { preventPopoverClose: boolean = false; state = { - id: this.props.id || makeId(), + id: this.props.id || htmlIdGenerator()(), isPopoverOpen: false, }; diff --git a/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap b/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap index b08ec8be4a3..5c600165aad 100644 --- a/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap +++ b/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap @@ -167,7 +167,7 @@ exports[`EuiSuperSelect props custom display is propagated to dropdown 1`] = ` data-focus-lock-disabled="disabled" >
() => 'generated-id'); +jest.mock('./../../../services/accessibility', () => ({ + htmlIdGenerator: () => () => 'generated-id', +})); jest.mock('../../portal', () => ({ EuiPortal: ({ children }: any) => children, })); // Mock the htmlIdGenerator to generate predictable ids for snapshot tests -jest.mock('../../../services/accessibility/html_id_generator', () => ({ - htmlIdGenerator: () => () => 'htmlId', -})); +// jest.mock('../../../services/accessibility/html_id_generator', () => ({ +// htmlIdGenerator: () => () => 'htmlId', +// })); const options = [ - { value: '1', inputDisplay: 'Option #1' }, - { value: '2', inputDisplay: 'Option #2' }, + { value: '1', inputDisplay: 'Option #1', describedby: 'generated-id' }, + { value: '2', inputDisplay: 'Option #2', describedby: 'generated-id' }, ]; describe('EuiSuperSelect', () => { diff --git a/src/components/form/super_select/super_select_control.test.tsx b/src/components/form/super_select/super_select_control.test.tsx index 5aae913b796..073dbce86ef 100644 --- a/src/components/form/super_select/super_select_control.test.tsx +++ b/src/components/form/super_select/super_select_control.test.tsx @@ -4,7 +4,9 @@ import { requiredProps } from '../../../test'; import { EuiSuperSelectControl } from './super_select_control'; -jest.mock('../form_row/make_id', () => () => 'generated-id'); +jest.mock('./../../../services/accessibility', () => ({ + htmlIdGenerator: () => () => 'generated-id', +})); describe('EuiSuperSelectControl', () => { test('is rendered', () => { diff --git a/src/components/form/super_select/super_select_control.tsx b/src/components/form/super_select/super_select_control.tsx index b55b26e815c..2431f456f71 100644 --- a/src/components/form/super_select/super_select_control.tsx +++ b/src/components/form/super_select/super_select_control.tsx @@ -9,7 +9,7 @@ import classNames from 'classnames'; import { CommonProps } from '../../common'; import { EuiScreenReaderOnly } from '../../accessibility'; -import makeId from '../form_row/make_id'; +import { htmlIdGenerator } from '../../../services/accessibility'; import { EuiFormControlLayout, EuiFormControlLayoutProps, @@ -85,7 +85,7 @@ export const EuiSuperSelectControl: ( side: 'right', }; - const screenReaderId = makeId(); + const screenReaderId = htmlIdGenerator()(); return ( diff --git a/src/components/form/switch/switch.test.tsx b/src/components/form/switch/switch.test.tsx index a564df98ca1..2d80bbcc764 100644 --- a/src/components/form/switch/switch.test.tsx +++ b/src/components/form/switch/switch.test.tsx @@ -10,7 +10,9 @@ const props = { onChange: () => {}, }; -jest.mock('../form_row/make_id', () => () => 'generated-id'); +jest.mock('./../../../services/accessibility', () => ({ + htmlIdGenerator: () => () => 'generated-id', +})); describe('EuiSwitch', () => { test('is rendered', () => { diff --git a/src/components/form/switch/switch.tsx b/src/components/form/switch/switch.tsx index d4e806f6574..b6e0143dd4c 100644 --- a/src/components/form/switch/switch.tsx +++ b/src/components/form/switch/switch.tsx @@ -8,7 +8,7 @@ import React, { import classNames from 'classnames'; import { CommonProps } from '../../common'; -import makeId from '../../form/form_row/make_id'; +import { htmlIdGenerator } from '../../../services/accessibility'; import { EuiIcon } from '../../icon'; export type EuiSwitchEvent = React.BaseSyntheticEvent< @@ -47,8 +47,8 @@ export const EuiSwitch: FunctionComponent = ({ type = 'button', ...rest }) => { - const [switchId] = useState(id || makeId()); - const [labelId] = useState(makeId()); + const [switchId] = useState(id || htmlIdGenerator()()); + const [labelId] = useState(htmlIdGenerator()()); const onClick = useCallback( (e: React.MouseEvent) => { diff --git a/src/components/header/header_alert/header_alert.test.tsx b/src/components/header/header_alert/header_alert.test.tsx index c64a0a6e272..0b3684df458 100644 --- a/src/components/header/header_alert/header_alert.test.tsx +++ b/src/components/header/header_alert/header_alert.test.tsx @@ -4,7 +4,9 @@ import { requiredProps } from '../../../test/required_props'; import { EuiHeaderAlert } from './header_alert'; -jest.mock('./../../form/form_row/make_id', () => () => 'generated-id'); +jest.mock('./../../../services/accessibility', () => ({ + htmlIdGenerator: () => () => 'generated-id', +})); describe('EuiHeaderAlert', () => { test('is rendered', () => { diff --git a/src/components/header/header_alert/header_alert.tsx b/src/components/header/header_alert/header_alert.tsx index cc7bf71582a..6586ce09cb1 100644 --- a/src/components/header/header_alert/header_alert.tsx +++ b/src/components/header/header_alert/header_alert.tsx @@ -4,7 +4,7 @@ import classNames from 'classnames'; import { CommonProps } from '../../common'; import { EuiFlexGroup, EuiFlexItem } from '../../flex'; -import makeId from '../../form/form_row/make_id'; +import { htmlIdGenerator } from '../../../services'; export type EuiHeaderAlertProps = CommonProps & Omit, 'title'> & { @@ -32,7 +32,7 @@ export const EuiHeaderAlert: FunctionComponent = ({ }) => { const classes = classNames('euiHeaderAlert', className); - const ariaId = makeId(); + const ariaId = htmlIdGenerator()(); return (
diff --git a/src/components/tabs/tabbed_content/tabbed_content.tsx b/src/components/tabs/tabbed_content/tabbed_content.tsx index 4d06397958d..daa1c41a70d 100644 --- a/src/components/tabs/tabbed_content/tabbed_content.tsx +++ b/src/components/tabs/tabbed_content/tabbed_content.tsx @@ -6,8 +6,6 @@ import { EuiTabs, EuiTabsDisplaySizes, EuiTabsSizes } from '../tabs'; import { EuiTab } from '../tab'; import { CommonProps } from '../../common'; -const makeId = htmlIdGenerator(); - /** * Marked as const so type is `['initial', 'selected']` instead of `string[]` */ @@ -66,7 +64,7 @@ export class EuiTabbedContent extends Component< autoFocus: 'initial', }; - private readonly rootId = makeId(); + private readonly rootId = htmlIdGenerator()(); private readonly divRef = createRef(); diff --git a/src/components/tool_tip/tool_tip.test.tsx b/src/components/tool_tip/tool_tip.test.tsx index 64f1d7ea302..f713a766f00 100644 --- a/src/components/tool_tip/tool_tip.test.tsx +++ b/src/components/tool_tip/tool_tip.test.tsx @@ -7,6 +7,10 @@ import { } from '../../test'; import { EuiToolTip } from './tool_tip'; +jest.mock('./../../services/accessibility', () => ({ + htmlIdGenerator: () => () => 'id', +})); + describe('EuiToolTip', () => { test('is rendered', () => { const component = render( diff --git a/src/components/tool_tip/tool_tip.tsx b/src/components/tool_tip/tool_tip.tsx index f543a5ff71e..ba2cc550857 100644 --- a/src/components/tool_tip/tool_tip.tsx +++ b/src/components/tool_tip/tool_tip.tsx @@ -11,9 +11,8 @@ import classNames from 'classnames'; import { keysOf } from '../common'; import { EuiPortal } from '../portal'; import { EuiToolTipPopover } from './tool_tip_popover'; -import { findPopoverPosition } from '../../services'; +import { findPopoverPosition, htmlIdGenerator } from '../../services'; -import makeId from '../form/form_row/make_id'; import { EuiResizeObserver } from '../observer/resize_observer'; export type ToolTipPositions = 'top' | 'right' | 'bottom' | 'left'; @@ -115,7 +114,7 @@ export class EuiToolTip extends Component { calculatedPosition: this.props.position, toolTipStyles: DEFAULT_TOOLTIP_STYLES, arrowStyles: undefined, - id: this.props.id || makeId(), + id: this.props.id || htmlIdGenerator()(), }; static defaultProps: Partial = { From e1e2b7f05170f86c6e095bf103161e77623f6a84 Mon Sep 17 00:00:00 2001 From: NightWing1998 Date: Fri, 20 Mar 2020 12:54:59 +0530 Subject: [PATCH 03/10] fixed linter error --- src-docs/src/views/button/button_group.js | 284 +++++++++------------- 1 file changed, 113 insertions(+), 171 deletions(-) diff --git a/src-docs/src/views/button/button_group.js b/src-docs/src/views/button/button_group.js index ccccf9013e7..aec021e8fd0 100644 --- a/src-docs/src/views/button/button_group.js +++ b/src-docs/src/views/button/button_group.js @@ -1,7 +1,4 @@ -import React, { - Component, - Fragment -} from 'react'; +import React, { Component, Fragment } from 'react'; import { EuiButtonGroup, @@ -9,12 +6,8 @@ import { EuiTitle, } from '../../../../src/components'; -import { - htmlIdGenerator -} from "../../../../src/services"; -import { - EuiPanel -} from '../../../../src/components/panel/panel'; +import { htmlIdGenerator } from '../../../../src/services'; +import { EuiPanel } from '../../../../src/components/panel/panel'; export default class extends Component { constructor(props) { @@ -24,7 +17,8 @@ export default class extends Component { const idPrefix2 = htmlIdGenerator()(); const idPrefix3 = htmlIdGenerator()(); - this.toggleButtons = [{ + this.toggleButtons = [ + { id: `${idPrefix}0`, label: 'Option one', }, @@ -38,7 +32,8 @@ export default class extends Component { }, ]; - this.toggleButtonsDisabled = [{ + this.toggleButtonsDisabled = [ + { id: `${idPrefix}3`, label: 'Option one', }, @@ -52,7 +47,8 @@ export default class extends Component { }, ]; - this.toggleButtonsMulti = [{ + this.toggleButtonsMulti = [ + { id: `${idPrefix2}0`, label: 'Option 1', }, @@ -66,7 +62,8 @@ export default class extends Component { }, ]; - this.toggleButtonsCompressed = [{ + this.toggleButtonsCompressed = [ + { id: `${idPrefix2}3`, label: 'fine', }, @@ -80,7 +77,8 @@ export default class extends Component { }, ]; - this.toggleButtonsIcons = [{ + this.toggleButtonsIcons = [ + { id: `${idPrefix3}0`, label: 'Align left', iconType: 'editorAlignLeft', @@ -97,7 +95,8 @@ export default class extends Component { }, ]; - this.toggleButtonsIconsMulti = [{ + this.toggleButtonsIconsMulti = [ + { id: `${idPrefix3}3`, label: 'Bold', name: 'bold', @@ -200,161 +199,104 @@ export default class extends Component { }; render() { - return ( < - Fragment > - < - EuiButtonGroup legend = "This is a basic group" - options = { - this.toggleButtons - } - idSelected = { - this.state.toggleIdSelected - } - onChange = { - this.onChange - } - /> < - EuiSpacer size = "m" / > - < - EuiTitle size = "xxs" > - < - h3 > Primary & amp; multi select < /h3> < / - EuiTitle > < - EuiSpacer size = "s" / > - < - EuiButtonGroup legend = "This is a primary group" - name = "primary" - options = { - this.toggleButtonsMulti - } - idToSelectedMap = { - this.state.toggleIdToSelectedMap - } - onChange = { - this.onChangeMulti - } - color = "primary" - type = "multi" / - > - < - EuiSpacer size = "m" / > - < - EuiTitle size = "xxs" > - < - h3 > Disabled & amp; full width < /h3> < / - EuiTitle > < - EuiSpacer size = "s" / > - < - EuiButtonGroup legend = "This is a disabled group" - name = "disabledGroup" - options = { - this.toggleButtonsDisabled - } - idSelected = { - this.state.toggleIdDisabled - } - onChange = { - this.onChangeDisabled - } - buttonSize = "m" - isDisabled isFullWidth / - > - < - EuiSpacer size = "m" / > - < - EuiTitle size = "xxs" > - < - h3 > Icons only < /h3> < / - EuiTitle > < - EuiSpacer size = "s" / > - < - EuiButtonGroup legend = "Text align" - name = "textAlign" - options = { - this.toggleButtonsIcons - } - idSelected = { - this.state.toggleIconIdSelected - } - onChange = { - this.onChangeIcons - } - isIconOnly / - > - & - nbsp; & nbsp; < - EuiButtonGroup legend = "Text style" - options = { - this.toggleButtonsIconsMulti - } - idToSelectedMap = { - this.state.toggleIconIdToSelectedMap - } - onChange = { - this.onChangeIconsMulti - } - type = "multi" - isIconOnly / - > - < - EuiSpacer / > - < - EuiPanel style = { - { - maxWidth: 300 - } - } > - < - EuiTitle size = "xxxs" > - < - h3 > - Compressed groups should always be fullWidth so they line up nicely in their small container. < - /h3> < / - EuiTitle > < - EuiSpacer size = "s" / > - < - EuiButtonGroup name = "coarsness" - legend = "This is a basic group" - options = { - this.toggleButtonsCompressed - } - idSelected = { - this.state.toggleCompressedIdSelected - } - onChange = { - this.onChangeCompressed - } - buttonSize = "compressed" - isFullWidth / - > - < - EuiSpacer / > - < - EuiTitle size = "xxxs" > - < - h3 > Unless they are icon only < /h3> < / - EuiTitle > < - EuiSpacer size = "s" / > - < - EuiButtonGroup name = "textStyleCompressed" - legend = "Text style" - className = "eui-displayInlineBlock" - options = { - this.toggleButtonsIconsMulti - } - idToSelectedMap = { - this.state.toggleIconIdToSelectedMapIcon - } - onChange = { - this.onChangeIconsMultiIcons - } - type = "multi" - buttonSize = "compressed" - isIconOnly / - > - < - /EuiPanel> < / - Fragment > + return ( + + + + +

Primary & amp; multi select

+
+ + + + +

Disabled & amp; full width

+
+ + + + +

Icons only

+
+ + +     + + + + +

+ Compressed groups should always be fullWidth so they line up + nicely in their small container.{' '} +

+
+ + + + +

Unless they are icon only

+
+ + +
+
); } } From 58249a80380ca1fef518e2845c963c824227acb5 Mon Sep 17 00:00:00 2001 From: Dhruvil Shah Date: Fri, 20 Mar 2020 13:34:28 +0530 Subject: [PATCH 04/10] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d059ac22ed0..261def592a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Added `Enter` key press functionality to `EuiSuperDatePicker` ([#3048](https://github.com/elastic/eui/pull/3048)) - Added `title` to headers of `EuiTable` in case of truncation ([#3094](https://github.com/elastic/eui/pull/3094)) - Added i18n to `EuiTableHeaderCell` ([#3094](https://github.com/elastic/eui/pull/3094)) +- Updated makeId to DEPRECATED, shifted all the calls to htmlIdGenerator **Bug Fixes** From 2e34237e7fc72bca41f3ea87f19a892942f16f00 Mon Sep 17 00:00:00 2001 From: NightWing1998 Date: Fri, 20 Mar 2020 18:24:57 +0530 Subject: [PATCH 05/10] updating deprecated warning --- src/components/form/form_row/make_id.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/form/form_row/make_id.ts b/src/components/form/form_row/make_id.ts index 71db07f5f4c..870f7ff549b 100644 --- a/src/components/form/form_row/make_id.ts +++ b/src/components/form/form_row/make_id.ts @@ -2,7 +2,7 @@ // inputs with their labels and other descriptive text elements. function makeId(): string { console.log( - 'WARNING: makeId is deprecated. Use htmlIdGenerator from services instead.' + 'WARNING: makeId is deprecated. Use htmlIdGenerator from @elastic/eui instead.' ); return Math.random() .toString(36) From 221fddf24de559342be399727742a1bdef8b6bba Mon Sep 17 00:00:00 2001 From: NightWing1998 Date: Thu, 26 Mar 2020 11:41:56 +0530 Subject: [PATCH 06/10] removing comments --- src-docs/src/views/button/button_group.js | 4 ++-- src/components/card/card.test.tsx | 1 - src/components/form/super_select/super_select.test.tsx | 5 ----- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src-docs/src/views/button/button_group.js b/src-docs/src/views/button/button_group.js index aec021e8fd0..5d259758a21 100644 --- a/src-docs/src/views/button/button_group.js +++ b/src-docs/src/views/button/button_group.js @@ -209,7 +209,7 @@ export default class extends Component { /> -

Primary & amp; multi select

+

Primary & multi select

-

Disabled & amp; full width

+

Disabled & full width

() => 'generated-id'); jest.mock('./../../services/accessibility', () => ({ htmlIdGenerator: () => () => 'generated-id', })); diff --git a/src/components/form/super_select/super_select.test.tsx b/src/components/form/super_select/super_select.test.tsx index 3114439a3fd..7eafbbfe1d1 100644 --- a/src/components/form/super_select/super_select.test.tsx +++ b/src/components/form/super_select/super_select.test.tsx @@ -12,11 +12,6 @@ jest.mock('../../portal', () => ({ EuiPortal: ({ children }: any) => children, })); -// Mock the htmlIdGenerator to generate predictable ids for snapshot tests -// jest.mock('../../../services/accessibility/html_id_generator', () => ({ -// htmlIdGenerator: () => () => 'htmlId', -// })); - const options = [ { value: '1', inputDisplay: 'Option #1', describedby: 'generated-id' }, { value: '2', inputDisplay: 'Option #2', describedby: 'generated-id' }, From 3729331a3866f8d55f524cd5ee0eab692bd039ab Mon Sep 17 00:00:00 2001 From: NightWing1998 Date: Fri, 27 Mar 2020 17:36:05 +0530 Subject: [PATCH 07/10] removing describedBy attributes --- .../super_select/__snapshots__/super_select.test.tsx.snap | 2 -- src/components/form/super_select/super_select.test.tsx | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap b/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap index 5c600165aad..cfc5bc26c57 100644 --- a/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap +++ b/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap @@ -1160,7 +1160,6 @@ exports[`EuiSuperSelect props options are rendered when select is open 1`] = `