diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md
index 397865b1de5183..8229445a68249c 100644
--- a/packages/dataviews/CHANGELOG.md
+++ b/packages/dataviews/CHANGELOG.md
@@ -15,6 +15,7 @@
### Enhancements
+- DataViews: Add `onReset` prop to control view reset functionality from the view config dropdown. [#75093](https://github.com/WordPress/gutenberg/pull/75093)
- DataForm: Add automatic field labeling - forms now automatically mark the minority of fields (required or optional) to reduce visual noise. [#74430](https://github.com/WordPress/gutenberg/pull/74430)
- DataViews: Add details form layout validation. [#74996](https://github.com/WordPress/gutenberg/pull/74996)
- Add new `adaptiveSelect` DataForm control. [#74937](https://github.com/WordPress/gutenberg/pull/74937)
diff --git a/packages/dataviews/README.md b/packages/dataviews/README.md
index a0db2568eb2e07..aa7e8ed5718119 100644
--- a/packages/dataviews/README.md
+++ b/packages/dataviews/README.md
@@ -478,6 +478,33 @@ Optional. Pass an object with a list of `perPageSizes` to control the available
An element to display when the `data` prop is empty. Defaults to `
No results
`.
+#### `onReset`: `( () => void ) | false`
+
+Callback function to reset the view to its default state, or `false` to indicate the view is not modified.
+
+- Type: `function` or `false`
+- Optional
+
+This prop controls the "Reset view" button in the view configuration dropdown:
+
+- When `undefined` (not provided): No reset functionality is shown. Use this when view persistence is not supported.
+- When `false`: The "Reset view" button is shown but disabled. Use this when view persistence is supported but the current view matches the default (not modified).
+- When a function: The "Reset view" button is shown and enabled. A blue dot indicator appears on the view options button to signal that the view has been modified. The function is called when the user clicks the reset button.
+
+Example:
+
+```jsx
+const { view, setView, isModified, resetToDefault } = useView( 'my-view-key' );
+
+
+```
+
### Styling
These are the CSS Custom Properties that can be used to tweak the appearance of the component:
diff --git a/packages/dataviews/src/components/dataviews-context/index.ts b/packages/dataviews/src/components/dataviews-context/index.ts
index ac1fc1cd024f7b..9061d9ba66c348 100644
--- a/packages/dataviews/src/components/dataviews-context/index.ts
+++ b/packages/dataviews/src/components/dataviews-context/index.ts
@@ -58,6 +58,7 @@ type DataViewsContextType< Item > = {
empty?: ReactNode;
hasInfiniteScrollHandler: boolean;
itemListLabel?: string;
+ onReset?: ( () => void ) | false;
};
const DataViewsContext = createContext< DataViewsContextType< any > >( {
diff --git a/packages/dataviews/src/components/dataviews-view-config/index.tsx b/packages/dataviews/src/components/dataviews-view-config/index.tsx
index dbb503b432f590..fe17610cfebe2b 100644
--- a/packages/dataviews/src/components/dataviews-view-config/index.tsx
+++ b/packages/dataviews/src/components/dataviews-view-config/index.tsx
@@ -14,9 +14,7 @@ import {
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
SelectControl,
- __experimentalGrid as Grid,
__experimentalHeading as Heading,
- __experimentalText as Text,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { __, _x } from '@wordpress/i18n';
@@ -247,46 +245,36 @@ function ItemsPerPageControl() {
);
}
-function SettingsSection( {
- title,
- description,
- children,
-}: {
- title: string;
- description?: string;
- children: React.ReactNode;
-} ) {
+function ResetViewButton() {
+ const { onReset } = useContext( DataViewsContext );
+
+ // Don't render if no persistence support (onReset is undefined)
+ if ( onReset === undefined ) {
+ return null;
+ }
+
+ const isDisabled = onReset === false;
+
return (
-
-