Skip to content
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

[EuiStat] Allow customizing the render of the title and description HTML tags #3676

Closed
cchaos opened this issue Jul 1, 2020 · 6 comments · Fixed by #3693
Closed

[EuiStat] Allow customizing the render of the title and description HTML tags #3676

cchaos opened this issue Jul 1, 2020 · 6 comments · Fixed by #3693

Comments

@cchaos
Copy link
Contributor

cchaos commented Jul 1, 2020

The error occurs when in the Stat component in the description you add something other than plain text, for example I include my own component, doing this generates a <div> tag inside a <p>, for example:

<p><div></div></p>

This produces a problem with React validation, to be more exact it shows this warning in console:

Warning: validateDOMnesting (...): <div> cannot appear as a descendant of <p>.

Modifying the <p> tags by <span> fixes this error and so you can use custom components, even other Eui components within stats.

Originally posted by @victorst79 in #3673 (comment)

@cchaos
Copy link
Contributor Author

cchaos commented Jul 1, 2020

Regarding the error, I thought that might be the case. EuiStat is pretty prescriptive with the elements it renders because they're being wrapped in EuiTitle and EuiText components which should be some level of text element (heading, paragraph, etc).

We will need to support some level of customizing these elements instead of just replacing the <p> tags with <span> tags. It will require updating props, TS types, tests, and docs.

Action item:

Add props like titleElement and descriptionElement to EuiStat and allow any(?) string to render that html tag as, defaulting to p.

@ashikmeerankutty
Copy link
Contributor

If an element other than a string is provided. What could we do for the screen reader. When I provided a div it was showing [object Object]

<Fragment>
{reverse ? `${title} ${description}` : `${description} ${title}`}
</Fragment>

@shrey
Copy link
Contributor

shrey commented Jul 2, 2020

@cchaos The description just straight out displays the text written inside it, could you guide me as to how to reproduce the bug.

        <EuiStat
          title="7,600 mm"
          description="<div><p>Total people</p></div>"
        />

@ashikmeerankutty
Copy link
Contributor

@cchaos The description just straight out displays the text written inside it, could you guide me as to how to reproduce the bug.

Check the console for a warning

@shrey
Copy link
Contributor

shrey commented Jul 2, 2020

@cchaos The description just straight out displays the text written inside it, could you guide me as to how to reproduce the bug.

Check the console for a warning

Screenshot 2020-07-02 at 5 42 06 PM
Still no warning though

@ashikmeerankutty
Copy link
Contributor

You passed the component as string. The component is not rendered here.
Try this:

<EuiStat title="7,600 mm" description={<div>Hello</div>} />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants