Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Breaking changes

- 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)
- DataViews: Custom `empty` elements are no longer wrapped in `<p>` tags to improve accessibility. [#71561](https://github.com/WordPress/gutenberg/pull/71561)

### Features

Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ Optional. Pass an object with a list of `perPageSizes` to control the available

#### `empty`: React node

A message or element to be displayed instead of the dataview's default empty message.
An element to display when the `data` prop is empty. Defaults to `<p>No results</p>`.

### Composition modes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) {
isItemClickable,
renderItemLink,
defaultLayouts,
empty = __( 'No results' ),
empty = <p>{ __( 'No results' ) }</p>,
} = useContext( DataViewsContext );

const ViewComponent = VIEW_LAYOUTS.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const CustomEmpty = () => {
onChangeView={ setView }
actions={ actions }
defaultLayouts={ defaultLayouts }
empty={ view.search ? 'No sites found' : 'No sites' }
empty={ <p>{ view.search ? 'No sites found' : 'No sites' }</p> }
/>
);
};
Expand Down
8 changes: 7 additions & 1 deletion packages/dataviews/src/dataviews-layouts/grid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,13 @@ function ViewGrid< Item >( {
'dataviews-no-results': ! isLoading,
} ) }
>
<p>{ isLoading ? <Spinner /> : empty }</p>
{ isLoading ? (
<p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need "p" around the spinner?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the <p> it can cause a jump in the dataview content when the view flips from the loading state to the empty state, because the vertical margin from the <p> appears all of a sudden.

I'm being super extra paranoid about this particular case because the default spinner and empty message elements are what appear in the Gutenberg editor. And I definitely do not want to introduce visual changes to the Gutenberg editor while working on this standalone component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I definitely do not want to introduce visual changes to the Gutenberg editor while working on this standalone component.

I like this reasoning 👍

<Spinner />
</p>
) : (
empty
) }
</div>
)
}
Expand Down
9 changes: 8 additions & 1 deletion packages/dataviews/src/dataviews-layouts/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,14 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) {
'dataviews-no-results': ! hasData && ! isLoading,
} ) }
>
{ ! hasData && <p>{ isLoading ? <Spinner /> : empty }</p> }
{ ! hasData &&
( isLoading ? (
<p>
<Spinner />
</p>
) : (
empty
) ) }
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,13 @@ function ViewPickerGrid< Item >( {
'dataviews-no-results': ! isLoading,
} ) }
>
<p>{ isLoading ? <Spinner /> : empty }</p>
{ isLoading ? (
<p>
<Spinner />
</p>
) : (
empty
) }
</div>
)
}
Expand Down
9 changes: 8 additions & 1 deletion packages/dataviews/src/dataviews-layouts/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,14 @@ function ViewTable< Item >( {
} ) }
id={ tableNoticeId }
>
{ ! hasData && <p>{ isLoading ? <Spinner /> : empty }</p> }
{ ! hasData &&
( isLoading ? (
<p>
<Spinner />
</p>
) : (
empty
) ) }
{ hasData && isLoading && (
<p className="dataviews-loading-more">
<Spinner />
Expand Down
Loading