-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update multiple functional components to useGeneratedHtmlId hook #5195
Conversation
- remove existing useMemo hook in favor of new helper - behavior should remain same as before
- replace useRefs with new hook - behavior should remain same as before
- replace useState with new hook - behavior should remain same as before
Preview documentation changes for this PR: https://eui.elastic.co/pr_5195/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QA before/after screencaps
@@ -156,7 +156,7 @@ export const EuiButtonGroup: FunctionComponent<Props> = ({ | |||
); | |||
|
|||
const typeIsSingle = type === 'single'; | |||
const nameIfSingle = name || htmlIdGenerator()(); | |||
const nameIfSingle = useGeneratedHtmlId({ conditionalId: name }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -244,7 +244,7 @@ export const EuiCard: FunctionComponent<EuiCardProps> = ({ | |||
className | |||
); | |||
|
|||
const ariaId = htmlIdGenerator()(); | |||
const ariaId = useGeneratedHtmlId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const switchId = useGeneratedHtmlId({ conditionalId: id }); | ||
const labelId = useGeneratedHtmlId({ conditionalId: labelProps?.id }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[QA] This is a cleanup refactor and no behavior should have changed on https://eui.elastic.co/pr_5195/#/forms/form-controls#switch
@@ -184,7 +184,7 @@ export const EuiKeyPadMenuItem: FunctionComponent<EuiKeyPadMenuItemProps> = ({ | |||
if (checkable) Element = 'label'; | |||
type ElementType = ReactElementType<typeof Element>; | |||
|
|||
const itemId = id || htmlIdGenerator()(); | |||
const itemId = useGeneratedHtmlId({ conditionalId: id }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const editorId = useMemo(() => _editorId || htmlIdGenerator()(), [ | ||
_editorId, | ||
]); | ||
const editorId = useGeneratedHtmlId({ conditionalId: _editorId }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[QA] This is a cleanup refactor and no behavior should have changed on https://eui.elastic.co/pr_5195/#/editors-syntax/markdown-editor
@@ -21,7 +21,7 @@ export const CheckboxMarkdownRenderer: FunctionComponent< | |||
const { replaceNode } = useContext(EuiMarkdownContext); | |||
return ( | |||
<EuiCheckbox | |||
id={htmlIdGenerator()()} | |||
id={useGeneratedHtmlId()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -113,7 +113,7 @@ export const EuiNotificationEvent: FunctionComponent<EuiNotificationEventProps> | |||
'euiNotificationEvent__title--isRead': isRead, | |||
}); | |||
|
|||
const randomHeadingId = htmlIdGenerator()(); | |||
const randomHeadingId = useGeneratedHtmlId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const resizerId = useGeneratedHtmlId({ | ||
prefix: 'resizable-button', | ||
conditionalId: id, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[QA] All resizable_container changes are cleanup refactors and no behavior should have changed on https://eui.elastic.co/pr_5195/#/layout/resizable-container
@@ -122,8 +122,7 @@ export const EuiTourStep: FunctionComponent<EuiTourStepProps> = ({ | |||
footerAction, | |||
...rest | |||
}) => { | |||
const generatedId = htmlIdGenerator(); | |||
const titleId = generatedId(); | |||
const titleId = useGeneratedHtmlId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preview documentation changes for this PR: https://eui.elastic.co/pr_5195/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Summary
Follow up to #5133: This PR updates our functional components to not regenerate our randomized HTML IDs on every component update/rerender.
Components addressed in separate PRs:
Components addressed in this PR:
Checklist
N/A - Individual component QA steps listed above.