From 3910eab3e8db99a4e049a838549d908f22e2ac95 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Thu, 19 Sep 2024 16:59:56 +0200 Subject: [PATCH] Dataviews config dropdown: remove style overrides (#65373) * Remove duplicate classname * Use `DropdownContentWrapper` and avoid style overrides * Extract popover props to const object * Move Dropdown under DataviewsViewConfigDropdown component * Add aria-expanded and aria-controls attributes to the dropdown toggle * Sort imports * Move DATAVIEWS_CONFIG_POPOVER_PROPS declaration at the top of the file * Do not memoize popover props --- Co-authored-by: ciampo Co-authored-by: stokesman Co-authored-by: tyxla --- .../dataviews-view-config/index.tsx | 92 +++++++++++-------- .../dataviews-view-config/style.scss | 13 +-- 2 files changed, 57 insertions(+), 48 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-view-config/index.tsx b/packages/dataviews/src/components/dataviews-view-config/index.tsx index 48fdf6906b0774..02e81b2b0913d8 100644 --- a/packages/dataviews/src/components/dataviews-view-config/index.tsx +++ b/packages/dataviews/src/components/dataviews-view-config/index.tsx @@ -8,6 +8,7 @@ import type { ChangeEvent } from 'react'; */ import { Button, + __experimentalDropdownContentWrapper as DropdownContentWrapper, Dropdown, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption, @@ -27,6 +28,7 @@ import { __, _x, sprintf } from '@wordpress/i18n'; import { memo, useContext, useMemo } from '@wordpress/element'; import { chevronDown, chevronUp, cog, seen, unseen } from '@wordpress/icons'; import warning from '@wordpress/warning'; +import { useInstanceId } from '@wordpress/compose'; /** * Internal dependencies @@ -55,6 +57,8 @@ interface ViewTypeMenuProps { defaultLayouts?: SupportedLayouts; } +const DATAVIEWS_CONFIG_POPOVER_PROPS = { placement: 'bottom-end', offset: 9 }; + function ViewTypeMenu( { defaultLayouts = { list: {}, grid: {}, table: {} }, }: ViewTypeMenuProps ) { @@ -510,7 +514,7 @@ function SettingsSection( { ); } -function DataviewsViewConfigContent( { +function DataviewsViewConfigDropdown( { density, setDensity, }: { @@ -518,25 +522,52 @@ function DataviewsViewConfigContent( { setDensity: React.Dispatch< React.SetStateAction< number > >; } ) { const { view } = useContext( DataViewsContext ); + const popoverId = useInstanceId( + _DataViewsViewConfig, + 'dataviews-view-config-dropdown' + ); + return ( - - - - - - - { view.type === LAYOUT_GRID && ( - { + return ( +