From c92914a38156baa971c86a149ae35879f968df0e Mon Sep 17 00:00:00 2001
From: Bree Hall <40739624+breehall@users.noreply.github.com>
Date: Thu, 14 Oct 2021 12:16:16 -0400
Subject: [PATCH] [Docs] Replace Static HTML Element IDs Generated IDs (Nav
Section) (#5224)
* Revised element IDs within the Accordion section of src/docs to use IDs generated the htmlIdGenerator utility function
* Revised element IDs within the Accordion section of src/docs to use IDs generated the useGeneratedHtmlId utility function
* Revised element IDs within the Flyout section of src/docs to use IDs generated the useGeneratedHtmlId utility function
* Revised element IDs within the Header section of src/docs to use IDs generated the useGeneratedHtmlId utility function
* Revised element IDs within the Header section of src/docs to use IDs generated the useGeneratedHtmlId utility function
* Revised element IDs within the Header section of src/docs to use IDs generated the useGeneratedHtmlId utility function
* Revised element IDs within the Modal section of src/docs to use IDs generated the useGeneratedHtmlId utility function
* Test commit
* Revised element IDs within the Resizable Panel section of src/docs to use the useGeneratedHtmlId utility function
* Revised element IDs within the Resizable Panel section of src/docs to use the useGeneratedHtmlId utility function
* Revised element IDs within the Button section of src/docs to use the useGeneratedHtmlId utility function
* Revised element IDs within the Button section of src/docs to use the useGeneratedHtmlId utility function
* Revised element IDs within the Collapsible Nav section of src/docs to use the useGeneratedHtmlId utility function
* Revised element IDs within the Context Menu section of src/docs to use the useGeneratedHtmlId utility function
* Revisions from PR
* Revised element IDs within the Keypad and Tabs sections of src/docs to use the useGeneratedHtmlId utility function
---
src-docs/src/views/button/button_group.js | 43 ++--
.../views/button/button_group_compressed.js | 28 ++-
src-docs/src/views/button/split_button.js | 6 +-
.../collapsible_nav/collapsible_nav_all.tsx | 209 +++++++++---------
.../src/views/context_menu/content_panel.js | 7 +-
.../src/views/context_menu/context_menu.js | 20 +-
.../context_menu/context_menu_with_content.js | 12 +-
.../src/views/context_menu/single_panel.js | 7 +-
src-docs/src/views/context_menu/small.js | 6 +-
.../key_pad_menu/key_pad_menu_checkable.js | 30 ++-
.../key_pad_menu_checkable_multi.js | 19 +-
.../key_pad_menu/key_pad_menu_item_button.js | 58 +++--
src-docs/src/views/tabs/tabs_flyout.tsx | 8 +-
src-docs/src/views/tabs/tabs_small.tsx | 4 +-
14 files changed, 290 insertions(+), 167 deletions(-)
diff --git a/src-docs/src/views/button/button_group.js b/src-docs/src/views/button/button_group.js
index 3766e4a815e..f6b8d0fded4 100644
--- a/src-docs/src/views/button/button_group.js
+++ b/src-docs/src/views/button/button_group.js
@@ -6,61 +6,72 @@ import {
EuiTitle,
} from '../../../../src/components';
-import { htmlIdGenerator } from '../../../../src/services';
-
-const idPrefix = htmlIdGenerator()();
-const idPrefix2 = htmlIdGenerator()();
+import { useGeneratedHtmlId } from '../../../../src/services';
export default () => {
+ const basicButtonGroupPrefix = useGeneratedHtmlId({
+ prefix: 'basicButtonGroup',
+ });
+ const multiSelectButtonGroupPrefix = useGeneratedHtmlId({
+ prefix: 'multiSelectButtonGroup',
+ });
+ const disabledButtonGroupPrefix = useGeneratedHtmlId({
+ prefix: 'disabledButtonGroup',
+ });
+
const toggleButtons = [
{
- id: `${idPrefix}0`,
+ id: `${basicButtonGroupPrefix}__0`,
label: 'Option one',
},
{
- id: `${idPrefix}1`,
+ id: `${basicButtonGroupPrefix}__1`,
label: 'Option two is selected by default',
},
{
- id: `${idPrefix}2`,
+ id: `${basicButtonGroupPrefix}__2`,
label: 'Option three',
},
];
const toggleButtonsDisabled = [
{
- id: `${idPrefix}3`,
+ id: `${disabledButtonGroupPrefix}__0`,
label: 'Option one',
},
{
- id: `${idPrefix}4`,
+ id: `${disabledButtonGroupPrefix}__1`,
label: 'Option two is selected by default',
},
{
- id: `${idPrefix}5`,
+ id: `${disabledButtonGroupPrefix}__2`,
label: 'Option three',
},
];
const toggleButtonsMulti = [
{
- id: `${idPrefix2}0`,
+ id: `${multiSelectButtonGroupPrefix}__0`,
label: 'Option 1',
},
{
- id: `${idPrefix2}1`,
+ id: `${multiSelectButtonGroupPrefix}__1`,
label: 'Option 2 is selected by default',
},
{
- id: `${idPrefix2}2`,
+ id: `${multiSelectButtonGroupPrefix}__2`,
label: 'Option 3',
},
];
- const [toggleIdSelected, setToggleIdSelected] = useState(`${idPrefix}1`);
- const [toggleIdDisabled, setToggleIdDisabled] = useState(`${idPrefix}4`);
+ const [toggleIdSelected, setToggleIdSelected] = useState(
+ `${basicButtonGroupPrefix}__1`
+ );
+ const [toggleIdDisabled, setToggleIdDisabled] = useState(
+ `${disabledButtonGroupPrefix}__1`
+ );
const [toggleIdToSelectedMap, setToggleIdToSelectedMap] = useState({
- [`${idPrefix2}1`]: true,
+ [`${multiSelectButtonGroupPrefix}__1`]: true,
});
const onChange = (optionId) => {
diff --git a/src-docs/src/views/button/button_group_compressed.js b/src-docs/src/views/button/button_group_compressed.js
index 1f18f82e351..6cd55c890ee 100644
--- a/src-docs/src/views/button/button_group_compressed.js
+++ b/src-docs/src/views/button/button_group_compressed.js
@@ -6,49 +6,53 @@ import {
EuiPanel,
} from '../../../../src/components';
-import { htmlIdGenerator } from '../../../../src/services';
-
-const idPrefix2 = htmlIdGenerator()();
-const idPrefix3 = htmlIdGenerator()();
+import { useGeneratedHtmlId } from '../../../../src/services';
export default () => {
+ const compressedToggleButtonGroupPrefix = useGeneratedHtmlId({
+ prefix: 'compressedToggleButtonGroup',
+ });
+ const multiSelectButtonGroupPrefix = useGeneratedHtmlId({
+ prefix: 'multiSelectButtonGroup',
+ });
+
const toggleButtonsCompressed = [
{
- id: `${idPrefix2}3`,
+ id: `${compressedToggleButtonGroupPrefix}__0`,
label: 'fine',
},
{
- id: `${idPrefix2}4`,
+ id: `${compressedToggleButtonGroupPrefix}__1`,
label: 'rough',
},
{
- id: `${idPrefix2}5`,
+ id: `${compressedToggleButtonGroupPrefix}__2`,
label: 'coarse',
},
];
const toggleButtonsIconsMulti = [
{
- id: `${idPrefix3}3`,
+ id: `${multiSelectButtonGroupPrefix}__0`,
label: 'Bold',
name: 'bold',
iconType: 'editorBold',
},
{
- id: `${idPrefix3}4`,
+ id: `${multiSelectButtonGroupPrefix}__1`,
label: 'Italic',
name: 'italic',
iconType: 'editorItalic',
isDisabled: true,
},
{
- id: `${idPrefix3}5`,
+ id: `${multiSelectButtonGroupPrefix}__2`,
label: 'Underline',
name: 'underline',
iconType: 'editorUnderline',
},
{
- id: `${idPrefix3}6`,
+ id: `${multiSelectButtonGroupPrefix}__3`,
label: 'Strikethrough',
name: 'strikethrough',
iconType: 'editorStrike',
@@ -60,7 +64,7 @@ export default () => {
setToggleIconIdToSelectedMapIcon,
] = useState({});
const [toggleCompressedIdSelected, setToggleCompressedIdSelected] = useState(
- `${idPrefix2}4`
+ `${compressedToggleButtonGroupPrefix}__1`
);
const onChangeCompressed = (optionId) => {
diff --git a/src-docs/src/views/button/split_button.js b/src-docs/src/views/button/split_button.js
index d813de7f6d1..61c6519a37c 100644
--- a/src-docs/src/views/button/split_button.js
+++ b/src-docs/src/views/button/split_button.js
@@ -9,9 +9,13 @@ import {
EuiContextMenuItem,
EuiPopover,
} from '../../../../src/components';
+import { useGeneratedHtmlId } from '../../../../src/services';
export default () => {
const [isPopoverOpen, setPopover] = useState(false);
+ const splitButtonPopoverId = useGeneratedHtmlId({
+ prefix: 'splitButtonPopover',
+ });
const onButtonClick = () => {
setPopover(!isPopoverOpen);
@@ -43,7 +47,7 @@ export default () => {
{
return `Unpin ${listItem.label}`;
}
- const collapsibleNav = (
- setNavIsOpen(!navIsOpen)}
- >
-
-
- }
- onClose={() => setNavIsOpen(false)}
- >
- {/* Dark deployments section */}
-
- {DeploymentsGroup}
-
+ const collapsibleNavId = useGeneratedHtmlId({ prefix: 'collapsibleNav' });
- {/* Shaded pinned section always with a home item */}
-
-
-
-
-
+ const collapsibleNav = () => {
+ return (
+ setNavIsOpen(!navIsOpen)}
+ >
+
+
+ }
+ onClose={() => setNavIsOpen(false)}
+ >
+ {/* Dark deployments section */}
+
+ {DeploymentsGroup}
+
-
+ {/* Shaded pinned section always with a home item */}
+
+
+
+
+
- {/* BOTTOM */}
-
- {/* Kibana section */}
- toggleAccordion(isOpen, 'Kibana')}
- >
-
-
+
- {/* Security callout */}
- {SecurityGroup}
+ {/* BOTTOM */}
+
+ {/* Kibana section */}
+ toggleAccordion(isOpen, 'Kibana')}
+ >
+
+
- {/* Learn section */}
- toggleAccordion(isOpen, 'Learn')}
- >
-
-
+ {/* Security callout */}
+ {SecurityGroup}
- {/* Docking button only for larger screens that can support it*/}
-
-
- toggleAccordion(isOpen, 'Learn')}
+ >
+ {
- setNavIsDocked(!navIsDocked);
- localStorage.setItem(
- 'nav2IsDocked',
- JSON.stringify(!navIsDocked)
- );
- }}
- iconType={navIsDocked ? 'lock' : 'lockOpen'}
+ gutterSize="none"
+ size="s"
/>
-
-
-
- );
+
+ {/* Docking button only for larger screens that can support it*/}
+
+
+ {
+ setNavIsDocked(!navIsDocked);
+ localStorage.setItem(
+ 'nav2IsDocked',
+ JSON.stringify(!navIsDocked)
+ );
+ }}
+ iconType={navIsDocked ? 'lock' : 'lockOpen'}
+ />
+
+
+
+
+ );
+ };
const leftSectionItems = [
collapsibleNav,
diff --git a/src-docs/src/views/context_menu/content_panel.js b/src-docs/src/views/context_menu/content_panel.js
index 8c1335874d5..fec20bd20ec 100644
--- a/src-docs/src/views/context_menu/content_panel.js
+++ b/src-docs/src/views/context_menu/content_panel.js
@@ -6,8 +6,13 @@ import {
EuiPopover,
} from '../../../../src/components';
+import { useGeneratedHtmlId } from '../../../../src/services';
+
export default () => {
const [isPopoverOpen, setPopover] = useState(false);
+ const customContextMenuPopoverId = useGeneratedHtmlId({
+ prefix: 'customContextMenuPopover',
+ });
const onButtonClick = () => {
setPopover(!isPopoverOpen);
@@ -30,7 +35,7 @@ export default () => {
return (
{
const [isPopoverOpen, setPopover] = useState(false);
+ const embeddedCodeSwitchId__1 = useGeneratedHtmlId({
+ prefix: 'embeddedCodeSwitch',
+ suffix: 'first',
+ });
+ const embeddedCodeSwitchId__2 = useGeneratedHtmlId({
+ prefix: 'embeddedCodeSwitch',
+ suffix: 'second',
+ });
+ const contextMenuPopoverId = useGeneratedHtmlId({
+ prefix: 'contextMenuPopover',
+ });
+
const onButtonClick = () => {
setPopover(!isPopoverOpen);
};
@@ -108,7 +122,7 @@ export default () => {
{}}
@@ -120,7 +134,7 @@ export default () => {
>
{}}
@@ -141,7 +155,7 @@ export default () => {
return (