diff --git a/CHANGELOG.md b/CHANGELOG.md index fcfefa2a5de..1571a1c8325 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fixed `EuiSuperDatePicker` to update `asyncInterval.isStopped` on a `isPaused` prop change. ([#2250](https://github.com/elastic/eui/pull/2250)) - Converted table, popover, buttons, pagination, outside click detector, focus trap, context menu, and panel to TypeScript ([#2212](https://github.com/elastic/eui/pull/2212)) +- Fixed `EuiStat` invalid DOM nesting due to a `

` tag nested within another `

` tag ([#2229](https://github.com/elastic/eui/pull/2229)) **Reverts** diff --git a/src/components/stat/__snapshots__/stat.test.tsx.snap b/src/components/stat/__snapshots__/stat.test.tsx.snap index e8c56233ea5..c9c4ec28361 100644 --- a/src/components/stat/__snapshots__/stat.test.tsx.snap +++ b/src/components/stat/__snapshots__/stat.test.tsx.snap @@ -10,20 +10,27 @@ exports[`EuiStat is rendered 1`] = ` class="euiText euiText--small euiStat__description" >

+

+ description title +

`; + + exports[`EuiStat props accent is rendered 1`] = `
+

+ description title +

`; @@ -54,17 +66,22 @@ exports[`EuiStat props center is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -76,17 +93,22 @@ exports[`EuiStat props danger is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -98,17 +120,22 @@ exports[`EuiStat props default is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -120,17 +147,22 @@ exports[`EuiStat props l is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -142,17 +174,22 @@ exports[`EuiStat props left is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -166,21 +203,22 @@ exports[`EuiStat props loading is rendered 1`] = ` class="euiText euiText--small euiStat__description" >

--

-

+

+ Statistic is loading +

`; @@ -192,17 +230,22 @@ exports[`EuiStat props m is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -214,17 +257,22 @@ exports[`EuiStat props primary is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -236,17 +284,22 @@ exports[`EuiStat props right is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -258,17 +311,22 @@ exports[`EuiStat props s is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -280,17 +338,22 @@ exports[`EuiStat props secondary is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -302,17 +365,22 @@ exports[`EuiStat props subdued is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -321,7 +389,7 @@ exports[`EuiStat props title and description are reversed 1`] = ` class="euiStat euiStat--leftAligned" > +

+ title description +

`; + exports[`EuiStat props xs is rendered 1`] = `
+

+ description title +

`; @@ -368,17 +447,22 @@ exports[`EuiStat props xxs is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; @@ -390,16 +474,21 @@ exports[`EuiStat props xxxs is rendered 1`] = ` class="euiText euiText--small euiStat__description" > +

+ description title +

`; diff --git a/src/components/stat/stat.tsx b/src/components/stat/stat.tsx index d3899e3911a..a5bf0b5cac1 100644 --- a/src/components/stat/stat.tsx +++ b/src/components/stat/stat.tsx @@ -9,8 +9,8 @@ import classNames from 'classnames'; import { EuiText } from '../text'; import { EuiTitle, EuiTitleSize } from '../title/title'; +import { EuiScreenReaderOnly } from '../accessibility'; import { EuiI18n } from '../i18n'; -import makeId from '../form/form_row/make_id'; const colorToClassNameMap = { default: null, @@ -79,8 +79,6 @@ export const EuiStat: FunctionComponent< className ); - const ariaId = makeId(); - const titleClasses = classNames( 'euiStat__title', colorToClassNameMap[titleColor], @@ -91,44 +89,38 @@ export const EuiStat: FunctionComponent< const descriptionDisplay = ( -

{description}

+
); - let titleText; - if (isLoading) { - titleText = ( - - {(loadingText: string) =>

--

} -
- ); - } else { - titleText = title; - } - const titleDisplay = ( -

{titleText}

+
); - let statDisplay; + const screenReader = ( + +

+ {isLoading ? ( + + ) : ( + + {reverse ? `${title} ${description}` : `${description} ${title}`} + + )} +

+
+ ); - if (reverse) { - statDisplay = ( - - {titleDisplay} - {descriptionDisplay} - - ); - } else { - statDisplay = ( - - {descriptionDisplay} - {titleDisplay} - - ); - } + const statDisplay = ( + + {!reverse && descriptionDisplay} + {titleDisplay} + {reverse && descriptionDisplay} + {screenReader} + + ); return (