-
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 3 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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |||||||||||||||||||||||||||||||||
| * Side Public License, v 1. | ||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import React, { FunctionComponent, HTMLAttributes } from 'react'; | ||||||||||||||||||||||||||||||||||
| import React, { FunctionComponent, HTMLAttributes, useMemo } from 'react'; | ||||||||||||||||||||||||||||||||||
| import classnames from 'classnames'; | ||||||||||||||||||||||||||||||||||
| import { CommonProps } from '../common'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -20,9 +20,14 @@ export const EuiModalHeaderTitle: EuiModalHeaderTitleProps = ({ | |||||||||||||||||||||||||||||||||
| ...rest | ||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||
| const classes = classnames('euiModalHeader__title', className); | ||||||||||||||||||||||||||||||||||
| const childrenWithHeading = useMemo(() => { | ||||||||||||||||||||||||||||||||||
| if (children && !children.hasOwnProperty('$$typeof')) | ||||||||||||||||||||||||||||||||||
| return <h1>{children}</h1>; | ||||||||||||||||||||||||||||||||||
| return children; | ||||||||||||||||||||||||||||||||||
| }, [children]); | ||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||
| <div className={classes} {...rest}> | ||||||||||||||||||||||||||||||||||
| {children} | ||||||||||||||||||||||||||||||||||
| {childrenWithHeading} | ||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| const childrenWithHeading = useMemo(() => { | |
| if (children && !children.hasOwnProperty('$$typeof')) | |
| return <h1>{children}</h1>; | |
| return children; | |
| }, [children]); | |
| return ( | |
| <div className={classes} {...rest}> | |
| {children} | |
| {childrenWithHeading} | |
| </div> | |
| ); | |
| return ( | |
| <div className={classes} {...rest}> | |
| {React.isValidElement(children) ? children : <h1>{children}</h1>} | |
| </div> | |
| ); |
LMK what you think!
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.
This feels a lot cleaner, and is the method I was hoping for, but not finding. Works great, and is easy to reason about.
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