-
Notifications
You must be signed in to change notification settings - Fork 860
[EuiModal] Wrapping header in H1 if a string is returned #5494
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
Changes from 2 commits
9449add
4909dbb
6a4d6a3
179a9fa
f665b8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,9 +20,14 @@ export const EuiModalHeaderTitle: EuiModalHeaderTitleProps = ({ | |||||||||||||||||||||||||||||||||||
| ...rest | ||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||
| const classes = classnames('euiModalHeader__title', className); | ||||||||||||||||||||||||||||||||||||
| const renderChildren = () => | ||||||||||||||||||||||||||||||||||||
| React.Children.map(children, (child) => { | ||||||||||||||||||||||||||||||||||||
| if (typeof child === 'string') return <h1>{child}</h1>; | ||||||||||||||||||||||||||||||||||||
| return child; | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||
| <div className={classes} {...rest}> | ||||||||||||||||||||||||||||||||||||
| {children} | ||||||||||||||||||||||||||||||||||||
| {renderChildren()} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| const renderChildren = () => | |
| React.Children.map(children, (child) => { | |
| if (typeof child === 'string') return <h1>{child}</h1>; | |
| return child; | |
| }); | |
| return ( | |
| <div className={classes} {...rest}> | |
| {children} | |
| {renderChildren()} | |
| const childrenWithHeading = useMemo(() => | |
| if (typeof children === 'string') return <h1>{children}</h1>; | |
| return children; | |
| }, [children]); | |
| return ( | |
| <div className={classes} {...rest}> | |
| {childrenWithHeading} |
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.
Good call @constancecchen. I refactored using your recommended approach, and found what I think is a better way to reason about children being a string than typeof. Source article here: https://overreacted.io/why-do-react-elements-have-typeof-property/
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.
Move up to
mainThere 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.
Thanks @thompsongl. I'll make this change and merge when tests pass.
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.
Don't forget the "Enable auto-merge" option also! It'll auto merge for ya when tests pass