Skip to content

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

Closed

Description

@cchaos

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)

Activity

  1. cchaos commented on Jul 1, 2020

    @cchaos
    ContributorAuthor

    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.

  2. ashikmeerankutty commented on Jul 1, 2020

    @ashikmeerankutty
    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>

  3. shrey commented on Jul 2, 2020

    @shrey
    Contributor

    @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>"
            />
    
  4. ashikmeerankutty commented on Jul 2, 2020

    @ashikmeerankutty
    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

  5. shrey commented on Jul 2, 2020

    @shrey
    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

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

  6. ashikmeerankutty commented on Jul 2, 2020

    @ashikmeerankutty
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions