From a4f6a067998245663c4524563a505b1525d6e187 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Mon, 11 Mar 2024 17:03:51 +0000 Subject: [PATCH] fix forwardRef view list --- packages/dataviews/src/view-list.js | 30 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index 7d4b322579a54..24ec8c93ee67f 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -6,6 +6,7 @@ import classNames from 'classnames'; /** * WordPress dependencies */ +import { forwardRef } from '@wordpress/element'; import { useAsyncList, useInstanceId } from '@wordpress/compose'; import { __experimentalHStack as HStack, @@ -135,18 +136,19 @@ function ListItem( { ); } -export default function ViewList( { - view, - fields, - data, - isLoading, - getItemId, - onSelectionChange, - onDetailsChange, - selection, - deferredRendering, - id: preferredId, -} ) { +const ViewList = forwardRef( ( props, ref ) => { + const { + view, + fields, + data, + isLoading, + getItemId, + onSelectionChange, + onDetailsChange, + selection, + deferredRendering, + id: preferredId, + } = props; const baseId = useInstanceId( ViewList, 'view-list', preferredId ); const shownData = useAsyncList( data, { step: 3 } ); const usedData = deferredRendering ? shownData : data; @@ -205,6 +207,7 @@ export default function ViewList( { className="dataviews-view-list" role="grid" store={ store } + ref={ ref } > { usedData.map( ( item ) => { const id = getItemDomId( item ); @@ -224,4 +227,5 @@ export default function ViewList( { } ) } ); -} +} ); +export default ViewList; \ No newline at end of file