Skip to content

Commit 8fec89d

Browse files
committed
Unwrap custom dataviews empty element from paragraph tags
The custom empty element can be anything arbitrary, including divs and headings. These elements are not semantically allowed to be children of paragraphs. The spinner continues to be wrapped in a paragraph. This is allowed semantically (the spinner is just an <svg> element), it keeps the vertical margins of the spinner consistent with the default empty message, and it is consistent with the spinners which show when the dataviews are loading more data in infinite scroll mode.
1 parent 3018c8b commit 8fec89d

File tree

8 files changed

+34
-7
lines changed

8 files changed

+34
-7
lines changed

packages/dataviews/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Breaking changes
66

77
- Remove `boolean` form control. Fields using `Edit: 'boolean'` must now use `Edit: 'checkbox'` or `Edit: 'toggle'` instead. Boolean field types now use checkboxes by default. [#71505](https://github.com/WordPress/gutenberg/pull/71505)
8+
- DataViews: Custom `empty` elements are no longer wrapped in `<p>` tags to improve accessibility. [#71561](https://github.com/WordPress/gutenberg/pull/71561)
89

910
### Features
1011

packages/dataviews/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ Optional. Pass an object with a list of `perPageSizes` to control the available
426426
427427
#### `empty`: React node
428428
429-
A message or element to be displayed instead of the dataview's default empty message.
429+
An element to display when the `data` prop is empty. Defaults to `<p>No results</p>`.
430430
431431
### Composition modes
432432

packages/dataviews/src/components/dataviews-layout/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) {
3737
isItemClickable,
3838
renderItemLink,
3939
defaultLayouts,
40-
empty = __( 'No results' ),
40+
empty = <p>{ __( 'No results' ) }</p>,
4141
} = useContext( DataViewsContext );
4242

4343
const ViewComponent = VIEW_LAYOUTS.find(

packages/dataviews/src/components/dataviews/stories/index.story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const CustomEmpty = () => {
155155
onChangeView={ setView }
156156
actions={ actions }
157157
defaultLayouts={ defaultLayouts }
158-
empty={ view.search ? 'No sites found' : 'No sites' }
158+
empty={ <p>{ view.search ? 'No sites found' : 'No sites' }</p> }
159159
/>
160160
);
161161
};

packages/dataviews/src/dataviews-layouts/grid/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,13 @@ function ViewGrid< Item >( {
474474
'dataviews-no-results': ! isLoading,
475475
} ) }
476476
>
477-
<p>{ isLoading ? <Spinner /> : empty }</p>
477+
{ isLoading ? (
478+
<p>
479+
<Spinner />
480+
</p>
481+
) : (
482+
empty
483+
) }
478484
</div>
479485
)
480486
}

packages/dataviews/src/dataviews-layouts/list/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,14 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) {
512512
'dataviews-no-results': ! hasData && ! isLoading,
513513
} ) }
514514
>
515-
{ ! hasData && <p>{ isLoading ? <Spinner /> : empty }</p> }
515+
{ ! hasData &&
516+
( isLoading ? (
517+
<p>
518+
<Spinner />
519+
</p>
520+
) : (
521+
empty
522+
) ) }
516523
</div>
517524
);
518525
}

packages/dataviews/src/dataviews-layouts/picker-grid/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,13 @@ function ViewPickerGrid< Item >( {
474474
'dataviews-no-results': ! isLoading,
475475
} ) }
476476
>
477-
<p>{ isLoading ? <Spinner /> : empty }</p>
477+
{ isLoading ? (
478+
<p>
479+
<Spinner />
480+
</p>
481+
) : (
482+
empty
483+
) }
478484
</div>
479485
)
480486
}

packages/dataviews/src/dataviews-layouts/table/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,14 @@ function ViewTable< Item >( {
578578
} ) }
579579
id={ tableNoticeId }
580580
>
581-
{ ! hasData && <p>{ isLoading ? <Spinner /> : empty }</p> }
581+
{ ! hasData &&
582+
( isLoading ? (
583+
<p>
584+
<Spinner />
585+
</p>
586+
) : (
587+
empty
588+
) ) }
582589
{ hasData && isLoading && (
583590
<p className="dataviews-loading-more">
584591
<Spinner />

0 commit comments

Comments
 (0)