The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
GDGT-1755: Migrate common components from deprecated Popover to Mantine Popover (#70503)
Stas Gavrylova0bea40dabf7
diff --git a/enterprise/frontend/src/metabase-enterprise/sandboxes/components/ParameterTargetWidget.jsx b/enterprise/frontend/src/metabase-enterprise/sandboxes/components/ParameterTargetWidget.jsxindex 412654afb4e..93888f16703 100644--- a/enterprise/frontend/src/metabase-enterprise/sandboxes/components/ParameterTargetWidget.jsx+++ b/enterprise/frontend/src/metabase-enterprise/sandboxes/components/ParameterTargetWidget.jsx@@ -1,61 +1,74 @@/* eslint-disable react/prop-types */import cx from "classnames";-import { Component, createRef } from "react";+import { useState } from "react";-import { PopoverWithTrigger } from "metabase/common/components/PopoverWithTrigger";import { SelectButton } from "metabase/common/components/SelectButton";+import { useCaptureEvent } from "metabase/common/hooks";import { ParameterTargetList } from "metabase/parameters/components/ParameterTargetList";import { getMappingOptionByTarget } from "metabase/parameters/utils/mapping-options";+import { Box, Popover } from "metabase/ui";-// eslint-disable-next-line import/no-default-export -- deprecated usage-export default class ParameterTargetWidget extends Component {- constructor(props) {- super(props);+const defaultChildren = ({ selected, placeholder }) => (+ <SelectButton hasValue={!!selected} className="border-med">+ {selected ? selected.name : placeholder || "Select a target"}+ </SelectButton>+);- this.popover = createRef();- }+// eslint-disable-next-line import/no-default-export -- deprecated usage+export default function ParameterTargetWidget({+ question,+ target,+ onChange,+ mappingOptions,+ placeholder,+ children = defaultChildren,+}) {+ const [isOpen, setIsOpen] = useState(false);- static defaultProps = {- children: ({ selected, placeholder }) => (- <SelectButton hasValue={!!selected} className="border-med">- {selected ? selected.name : placeholder || "Select a target"}- </SelectButton>- ),- };+ useCaptureEvent(+ "keydown",+ (e) => {+ if (e.key === "Escape") {+ e.stopImmediatePropagation();+ setIsOpen(false);+ }+ },+ { enabled: isOpen },+ );- render() {- const {- question,- target,- onChange,- mappingOptions,- placeholder,- children,- } = this.props;+ const disabled = mappingOptions.length === 0;+ const selected = getMappingOptionByTarget(mappingOptions, target, question);- const disabled = mappingOptions.length === 0;- const selected = getMappingOptionByTarget(mappingOptions, target, question);+ const triggerElement =+ typeof children === "function"+ ? children({ selected, disabled, placeholder })+ : children;- return (- <PopoverWithTrigger- ref={this.popover}- triggerClasses={cx({ disabled: disabled })}- sizeToFit- triggerElement={- typeof children === "function"- ? children({ selected, disabled, placeholder })- : children- }- >+ return (+ <Popover+ withinPortal={false}+ position="bottom-start"+ closeOnClickOutside+ trapFocus+ disabled={disabled}+ opened={isOpen}+ onChange={setIsOpen}+ >+ <Popover.Target>+ <Box className={cx({ disabled })} onClick={() => setIsOpen(!isOpen)}>+ {triggerElement}+ </Box>+ </Popover.Target>+ <Popover.Dropdown style={{ boxSizing: "content-box" }}><ParameterTargetListonChange={(target) => {onChange(target);- this.popover.current.close();+ setIsOpen(false);}}mappingOptions={mappingOptions}selectedMappingOption={selected}/>- </PopoverWithTrigger>- );- }+ </Popover.Dropdown>+ </Popover>+ );}diff --git a/enterprise/frontend/src/metabase-enterprise/sandboxes/index.js b/enterprise/frontend/src/metabase-enterprise/sandboxes/index.jsindex 40c8739c630..a87d768047c 100644--- a/enterprise/frontend/src/metabase-enterprise/sandboxes/index.js+++ b/enterprise/frontend/src/metabase-enterprise/sandboxes/index.js@@ -68,6 +68,7 @@ export function initializePlugin() {key=":tableId/segmented"path=":tableId/segmented"modal={EditSandboxingModal}+ modalProps={{ enableMouseEvents: true }}/>,);PLUGIN_ADMIN_PERMISSIONS_TABLE_GROUP_ROUTES.push(@@ -75,6 +76,7 @@ export function initializePlugin() {key="segmented/group/:groupId"path="segmented/group/:groupId"modal={EditSandboxingModal}+ modalProps={{ enableMouseEvents: true }}/>,);PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_OPTIONS.push(OPTION_SEGMENTED);diff --git a/frontend/src/metabase/admin/settings/components/widgets/GroupMappingsWidget/GroupSelect/GroupSelect.tsx b/frontend/src/metabase/admin/settings/components/widgets/GroupMappingsWidget/GroupSelect/GroupSelect.tsxindex da25a0dc187..af5a113f7f8 100644--- a/frontend/src/metabase/admin/settings/components/widgets/GroupMappingsWidget/GroupSelect/GroupSelect.tsx+++ b/frontend/src/metabase/admin/settings/components/widgets/GroupMappingsWidget/GroupSelect/GroupSelect.tsx@@ -3,7 +3,6 @@ import { t } from "ttag";import { GroupSummary } from "metabase/admin/people/components/GroupSummary";import type { GroupIds, UserGroupType } from "metabase/admin/types";-import { PopoverWithTrigger } from "metabase/common/components/PopoverWithTrigger";import { Select } from "metabase/common/components/Select";import CS from "metabase/css/core/index.css";import {@@ -13,7 +12,7 @@ import {isDefaultGroup,} from "metabase/lib/groups";import { isNotNull } from "metabase/lib/types";-import { Icon } from "metabase/ui";+import { Box, Icon, Popover } from "metabase/ui";import { color } from "metabase/ui/colors";import type { GroupInfo } from "metabase-types/api";@@ -78,9 +77,12 @@ export const GroupSelect = ({if (groups.length === 0) {return (- <PopoverWithTrigger triggerElement={triggerElement}>- <span className={CS.p1}>{emptyListMessage}</span>- </PopoverWithTrigger>+ <Popover withinPortal={false} position="bottom-start">+ <Popover.Target>{triggerElement}</Popover.Target>+ <Popover.Dropdown style={{ boxSizing: "border-box" }}>+ <Box p="sm">{emptyListMessage}</Box>+ </Popover.Dropdown>+ </Popover>);}diff --git a/frontend/src/metabase/common/components/Popover/Popover.jsx b/frontend/src/metabase/common/components/Popover/Popover.jsxdeleted file mode 100644index 252e0f53acb..00000000000--- a/frontend/src/metabase/common/components/Popover/Popover.jsx+++ /dev/null@@ -1,437 +0,0 @@-import cx from "classnames";-import PropTypes from "prop-types";-import { Children, Component, cloneElement } from "react";-import ReactDOM from "react-dom";-import Tether from "tether";--import { OnClickOutsideWrapper } from "metabase/common/components/OnClickOutsideWrapper";-import CS from "metabase/css/core/index.css";-import { getPortalRootElement } from "metabase/css/core/overlays/utils";-import ZIndex from "metabase/css/core/z-index.module.css";-import { isCypressActive } from "metabase/env";--import PopoverS from "./Popover.module.css";--// space we should leave between page edge and popover edge-const PAGE_PADDING = 10;-// Popover padding and border-const POPOVER_BODY_PADDING = 2;--export class Popover extends Component {- constructor(props, context) {- super(props, context);-- this.state = {- width: null,- height: null,- };-- this.handleDismissal = this.handleDismissal.bind(this);- }-- static propTypes = {- id: PropTypes.string,- isOpen: PropTypes.bool,- hasArrow: PropTypes.bool,- hasBackground: PropTypes.bool,- tetherOptions: PropTypes.object,- // used to prevent popovers from being taller than the screen- sizeToFit: PropTypes.bool,- pinInitialAttachment: PropTypes.bool,- // most popovers have a max-width to prevent them from being overly wide- // in the case their content is of an unexpected length- // noMaxWidth allows that to be overridden in cases where popovers should- // expand alongside their contents contents- autoWidth: PropTypes.bool,- // prioritized vertical attachments points on the popover- verticalAttachments: PropTypes.array,- // prioritized horizontal attachment points on the popover- horizontalAttachments: PropTypes.array,- // by default we align the top edge of the target to the bottom edge of the- // popover or vice versa. This causes the same edges to be aligned- alignVerticalEdge: PropTypes.bool,- // by default we align the popover to the center of the target. This- // causes the edges to be aligned- alignHorizontalEdge: PropTypes.bool,- // don't wrap the popover in an OnClickOutsideWrapper- noOnClickOutsideWrapper: PropTypes.bool,- targetOffsetX: PropTypes.number,- targetOffsetY: PropTypes.number,- onClose: PropTypes.func,- containerClassName: PropTypes.string,- className: PropTypes.string,- style: PropTypes.object,- children: PropTypes.oneOfType([- PropTypes.element,- PropTypes.func,- PropTypes.array,- ]),- target: PropTypes.any,- targetEvent: PropTypes.object,- role: PropTypes.string,- ignoreTrigger: PropTypes.bool,- };-- static defaultProps = {- isOpen: true,- hasArrow: false,- hasBackground: true,- verticalAttachments: ["top", "bottom"],- horizontalAttachments: ["left", "right"],- alignVerticalEdge: false,- alignHorizontalEdge: true,- targetOffsetX: 0,- targetOffsetY: 5,- sizeToFit: false,- autoWidth: false,- noOnClickOutsideWrapper: false,- containerClassName: "",- ignoreTrigger: false,- };-- _getPopoverElement(isOpen) {- // 3s is an overkill for Cypress, but let's start with it and dial it down- // if we see that the flakes don't appear anymore- const resizeTimer = isCypressActive ? 3000 : 100;-- if (!this._popoverElement && isOpen) {- const portalRootElement = getPortalRootElement();-- this._popoverElement = document.createElement("span");- this._popoverElement.className = cx(- PopoverS.PopoverContainer,- ZIndex.Overlay,- this.props.containerClassName,- );- this._popoverElement.dataset.testid = "popover";-- portalRootElement.appendChild(this._popoverElement);-- this._timer = setInterval(() => {- const { width, height } = this._popoverElement.getBoundingClientRect();- if (this.state.width !== width || this.state.height !== height) {- this.setState({ width, height });- }- }, resizeTimer);- }- return this._popoverElement;- }-- componentDidMount() {- this.updateComponentPosition(this.props.isOpen);- }-- updateComponentPosition(isOpen) {- if (!isOpen) {- return;- }-- const tetherOptions = {- bodyElement: getPortalRootElement(),- element: this._popoverElement,- target: this._getTargetElement(),- };-- if (!this._best || !this.props.pinInitialAttachment) {- let best = {- attachmentX: "center",- attachmentY: "top",- targetAttachmentX: "center",- targetAttachmentY: "bottom",- offsetX: 0,- offsetY: 0,- };-- // horizontal- best = this._getBestAttachmentOptions(- tetherOptions,- best,- this.props.horizontalAttachments,- ["left", "right"],- (best, attachmentX) => ({- ...best,- attachmentX: attachmentX,- targetAttachmentX: this.props.alignHorizontalEdge- ? attachmentX- : "center",- offsetX: {- center: 0,- left: -this.props.targetOffsetX,- right: this.props.targetOffsetX,- }[attachmentX],- }),- );-- // vertical- best = this._getBestAttachmentOptions(- tetherOptions,- best,- this.props.verticalAttachments,- ["top", "bottom"],- (best, attachmentY) => ({- ...best,- attachmentY: attachmentY,- targetAttachmentY: (- this.props.alignVerticalEdge- ? attachmentY === "bottom"- : attachmentY === "top"- )- ? "bottom"- : "top",- offsetY: {- top: this.props.targetOffsetY,- bottom: -this.props.targetOffsetY,- }[attachmentY],- }),- );-- this._best = best;- }-- if (this.props.sizeToFit) {- if (this._best.targetAttachmentY === "top") {- this.constrainPopoverToBetweenViewportAndTarget(tetherOptions, "top");- } else if (this._best.targetAttachmentY === "bottom") {- this.constrainPopoverToBetweenViewportAndTarget(- tetherOptions,- "bottom",- );- }- }-- // finally set the best options- this._setTetherOptions(tetherOptions, this._best);- }-- componentDidUpdate() {- this.updateComponentPosition(this.props.isOpen);- }-- componentWillUnmount() {- if (this._tether) {- this._tether.destroy();- delete this._tether;- }-- if (this._popoverElement) {- if (this._popoverElement.parentNode) {- this._popoverElement.parentNode.removeChild(this._popoverElement);- }-- delete this._popoverElement;- clearInterval(this._timer);- delete this._timer;- }- }-- handleDismissal(...args) {- if (this.props.onClose) {- this.props.onClose(...args);- }- }-- _popoverComponent() {- const childProps = {- maxHeight: this._getMaxHeight(),- };- const content = (- <div- id={this.props.id}- data-element-id="legacy-popover"- className={cx(- PopoverS.PopoverBody,- {- [PopoverS.PopoverBodyWithBackground]: this.props.hasBackground,- [PopoverS.PopoverBodyWithArrow]:- this.props.hasArrow && this.props.hasBackground,- [PopoverS.PopoverBodyAutoWidth]: this.props.autoWidth,- },- // TODO kdoh 10/16/2017 we should eventually remove this- this.props.className,- )}- role={this.props.role}- style={this.props.style}- >- {typeof this.props.children === "function"- ? this.props.children(childProps)- : Children.count(this.props.children) === 1 &&- // NOTE: workaround for https://github.com/facebook/react/issues/12136- !Array.isArray(this.props.children)- ? cloneElement(Children.only(this.props.children), childProps)- : this.props.children}- </div>- );- if (this.props.noOnClickOutsideWrapper) {- return content;- } else {- return (- <OnClickOutsideWrapper- handleDismissal={this.handleDismissal}- ignoreElement={- this.props.ignoreTrigger ? this._getTargetElement() : undefined- }- >- {content}- </OnClickOutsideWrapper>- );- }- }-- _setTetherOptions(tetherOptions, o) {- if (o) {- tetherOptions = {- ...tetherOptions,- attachment: `${o.attachmentY} ${o.attachmentX}`,- targetAttachment: `${o.targetAttachmentY} ${o.targetAttachmentX}`,- targetOffset: `${o.offsetY}px ${o.offsetX}px`,- };- }- if (this._tether) {- this._tether.setOptions(tetherOptions);- } else {- this._tether = new Tether(tetherOptions);- }- }-- _getMaxHeight() {- const { top, bottom } = this._getTargetElement().getBoundingClientRect();-- let attachments;- if (this.props.pinInitialAttachment && this._best) {- // if we have a pinned attachment only use that- attachments = [this._best.attachmentY];- } else {- // otherwise use the verticalAttachments prop- attachments = this.props.verticalAttachments;- }-- const availableHeights = attachments.map((attachmentY) =>- attachmentY === "top"- ? window.innerHeight - bottom - this.props.targetOffsetY - PAGE_PADDING- : attachmentY === "bottom"- ? top - this.props.targetOffsetY - PAGE_PADDING- : 0,- );-- // get the largest available height, then subtract .PopoverBody's border and padding- return Math.max(...availableHeights) - POPOVER_BODY_PADDING;- }-- _getBestAttachmentOptions(- tetherOptions,- options,- attachments,- offscreenProps,- getAttachmentOptions,- ) {- let best = { ...options };- let bestOffScreen = -Infinity;- // try each attachment until one is entirely on screen, or pick the least bad one- for (const attachment of attachments) {- // compute the options for this attachment position then set it- const options = getAttachmentOptions(best, attachment);- this._setTetherOptions(tetherOptions, options);-- // get bounds within *document*- const elementRect = Tether.Utils.getBounds(tetherOptions.element);-- // get bounds within *window*- const doc = document.documentElement;- const left =- (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);- const top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);- elementRect.top -= top;- elementRect.bottom += top;- elementRect.left -= left;- elementRect.right += left;-- // test to see how much of the popover is off-screen- const offScreen = offscreenProps- .map((prop) => Math.min(elementRect[prop], 0))- .reduce((a, b) => a + b);- // if none then we're done, otherwise check to see if it's the best option so far- if (offScreen === 0) {- best = options;- break;- } else if (offScreen > bestOffScreen) {- best = options;- bestOffScreen = offScreen;- }- }- return best;- }-- _getTargetElement() {- let target;-- if (this.props.targetEvent) {- // create a fake element at the event coordinates- target = document.getElementById("popover-event-target");-- if (!target) {- target = document.createElement("div");- target.id = "popover-event-target";- document.body.appendChild(target);- }-- target.style.left = this.props.targetEvent.clientX - 3 + "px";- target.style.top = this.props.targetEvent.clientY - 3 + "px";- } else if (this.props.target) {- if (typeof this.props.target === "function") {- target = this.props.target();- } else {- target = this.props.target;- }- }-- if (target == null) {- target = this._popoverElement;- }-- return target;- }-- constrainPopoverToBetweenViewportAndTarget(tetherOptions, direction) {- const body = tetherOptions.element.querySelector(- "[data-element-id=legacy-popover]",- );- const target = this._getTargetElement();- const bodyHeight = body.getBoundingClientRect().height;- const space =- direction === "top"- ? target.getBoundingClientRect().top- : window.innerHeight - target.getBoundingClientRect().bottom;- const maxHeight = space - PAGE_PADDING;- if (bodyHeight > maxHeight) {- body.style.maxHeight = maxHeight + "px";- body.classList.add(CS.scrollY);- body.classList.add(CS.scrollShow);- }- }-- render() {- const isOpen = this.props.isOpen;-- const popoverElement = this._getPopoverElement(isOpen);- if (popoverElement) {- if (isOpen) {- popoverElement.classList.add("PopoverContainer--open");- popoverElement.classList.add("popover");- popoverElement.dataset.state = "visible";- } else {- popoverElement.classList.remove("PopoverContainer--open");- popoverElement.classList.remove("popover");- popoverElement.dataset.state = "hidden";- }- }-- if (isOpen) {- return ReactDOM.createPortal(- <span>{isOpen ? this._popoverComponent() : null}</span>,- popoverElement,- );- }-- return <span className={CS.hide} />;- }-}diff --git a/frontend/src/metabase/common/components/Popover/Popover.module.css b/frontend/src/metabase/common/components/Popover/Popover.module.cssindex 01ec29774b5..1093f312aa7 100644--- a/frontend/src/metabase/common/components/Popover/Popover.module.css+++ b/frontend/src/metabase/common/components/Popover/Popover.module.css@@ -1,26 +1,4 @@-/* afaik popover needs a positioning context to be able to calculate the transform */-.PopoverContainer {- position: absolute;-}--.PopoverBody {- pointer-events: auto;- min-width: 1em; /* ewwwwwwww */- display: flex;- flex-direction: column;-- /* add a max-width so that long strings don't cause the popover to expand- * see metabase#4930 */- max-width: 500px;-}--.PopoverBody.PopoverBodyWithBackground {- border: 1px solid var(--mb-color-border);- box-shadow: 0 4px 10px var(--mb-color-shadow);- background-color: var(--mb-color-background-primary);- border-radius: 6px;- overflow: auto;-}+/* TODO: Remove this file when tippy.js dependency is removed *//* Global classes from tippy.js */:global(.tippy-box),@@ -66,101 +44,8 @@padding: 0;}-/* remove the max-width in cases where the popover content needs to expand- * initially added for date pickers so the dual date picker can fully- * expand as necessary - metabase#5971- */-.PopoverBody.PopoverBodyAutoWidth {- max-width: none;-}--/* shared arrow styles */-.PopoverBodyWithArrow::before,-.PopoverBodyWithArrow::after {- position: absolute;- content: "";- display: block;- border-left: 10px solid transparent;- border-right: 10px solid transparent;- border-top: 10px solid transparent;- border-bottom: 10px solid transparent;- pointer-events: none;-}--/* As Popover footer uses absolute positioning- * to stick to bottom, options lists and other- * middle content need extra margin-bottom- */-.PopoverBodyMarginBottom {- margin-bottom: 60px;-}--.PopoverBody .FormField {- margin-bottom: 0.75rem;-}--.PopoverFooter {- background: white;- position: absolute;- bottom: 0;- border-top: 1px solid var(--mb-color-border);- border-bottom-right-radius: 6px;- border-bottom-left-radius: 6px;- padding-top: 8px;- width: 100%;-- /* Without z-index; calendar days, if selected, scroll above this component */- z-index: 1;-}--/* Global tether (tippy.js dependency) classes */-/* create a slightly larger arrow on the top for border purposes */-:global(.tether-element-attached-top) .PopoverBodyWithArrow::before {- top: -20px;- border-bottom-color: var(--mb-color-border);-}--/* create a smaller inset arrow on the top */-:global(.tether-element-attached-top) .PopoverBodyWithArrow::after {- top: -18px;- border-bottom-color: var(--mb-color-background-primary);-}--/* create a slightly larger arrow on the bottom for border purposes */-:global(.tether-element-attached-bottom) .PopoverBodyWithArrow::before {- bottom: -20px;- border-top-color: var(--mb-color-border);-}--/* create a smaller inset arrow on the bottom */-:global(.tether-element-attached-bottom) .PopoverBodyWithArrow::after {- bottom: -18px;- border-top-color: var(--mb-color-background-primary);-}--/* if the tether element is attached right, move our arrows right */-:global(.tether-target-attached-right) .PopoverBodyWithArrow::before,-:global(.tether-target-attached-right) .PopoverBodyWithArrow::after {- right: 12px;-}--/* if the tether element is attached center, move our arrows to the center */-:global(.tether-element-attached-center) .PopoverBodyWithArrow::before,-:global(.tether-element-attached-center) .PopoverBodyWithArrow::after {- margin-left: 50%;- left: -10px;-}--:global(.tether-element-attached-right) .PopoverBodyWithArrow::before,-:global(.tether-element-attached-right) .PopoverBodyWithArrow::after {- right: 12px;-}--:global(.tether-element-attached-left) .PopoverBodyWithArrow::before,-:global(.tether-element-attached-left) .PopoverBodyWithArrow::after {- left: 12px;-}-+/* Global id for an element used for positioning tooltips.+ * Check usage in metabase/lib/dom.ts when removing this component. */:global(#popover-event-target) {position: fixed;width: 6px;diff --git a/frontend/src/metabase/common/components/Popover/TippyPopover.tsx b/frontend/src/metabase/common/components/Popover/TippyPopover.tsxindex 177079beec4..6318d40592e 100644--- a/frontend/src/metabase/common/components/Popover/TippyPopover.tsx+++ b/frontend/src/metabase/common/components/Popover/TippyPopover.tsx@@ -13,6 +13,7 @@ import { isReducedMotionPreferred } from "metabase/lib/dom";import type { SizeToFitOptions } from "./SizeToFitModifier";import { sizeToFitModifierFn } from "./SizeToFitModifier";+import "./Popover.module.css";const TippyComponent = TippyReact.default;type TippyProps = TippyReact.TippyProps;diff --git a/frontend/src/metabase/common/components/Popover/index.ts b/frontend/src/metabase/common/components/Popover/index.tsdeleted file mode 100644index 7ce91dd5a79..00000000000--- a/frontend/src/metabase/common/components/Popover/index.ts+++ /dev/null@@ -1 +0,0 @@-export { Popover } from "./Popover";diff --git a/frontend/src/metabase/common/components/PopoverWithTrigger/PopoverWithTrigger.tsx b/frontend/src/metabase/common/components/PopoverWithTrigger/PopoverWithTrigger.tsxdeleted file mode 100644index 227e8a2b8f9..00000000000--- a/frontend/src/metabase/common/components/PopoverWithTrigger/PopoverWithTrigger.tsx+++ /dev/null@@ -1,7 +0,0 @@-import { Popover } from "metabase/common/components/Popover";-import { Triggerable } from "metabase/common/components/Triggerable";--/**- * @deprecated prefer Popover from "metabase/ui"- */-export const PopoverWithTrigger = Triggerable(Popover);diff --git a/frontend/src/metabase/common/components/PopoverWithTrigger/index.ts b/frontend/src/metabase/common/components/PopoverWithTrigger/index.tsdeleted file mode 100644index daee45af87c..00000000000--- a/frontend/src/metabase/common/components/PopoverWithTrigger/index.ts+++ /dev/null@@ -1 +0,0 @@-export { PopoverWithTrigger } from "./PopoverWithTrigger";diff --git a/frontend/src/metabase/common/components/Select/Select.tsx b/frontend/src/metabase/common/components/Select/Select.tsxindex 681188cce67..70f0c0563d3 100644--- a/frontend/src/metabase/common/components/Select/Select.tsx+++ b/frontend/src/metabase/common/components/Select/Select.tsx@@ -14,14 +14,12 @@ import {AccordionList,type SearchProps,} from "metabase/common/components/AccordionList";-import { PopoverWithTrigger } from "metabase/common/components/PopoverWithTrigger";import type { SelectButtonProps } from "metabase/common/components/SelectButton";import { SelectButton } from "metabase/common/components/SelectButton";import CS from "metabase/css/core/index.css";import Uncontrollable from "metabase/hoc/Uncontrollable";-import { composeEventHandlers } from "metabase/lib/compose-event-handlers";import type { IconName } from "metabase/ui";-import { Icon } from "metabase/ui";+import { Icon, Popover } from "metabase/ui";const MIN_ICON_WIDTH = 20;@@ -45,7 +43,7 @@ export interface SelectProps<disabled?: boolean;hiddenIcons?: boolean;- // PopoverWithTrigger props+ // Popover propsisInitiallyOpen?: boolean;triggerElement?: ReactNode;onClose?: () => void;@@ -99,11 +97,14 @@ export interface SelectChangeTarget<TValue> {value: TValue;}+interface SelectState {+ isPopoverOpen: boolean;+}+class BaseSelect<TValue,TOption extends object = SelectOption<TValue>,-> extends Component<SelectProps<TValue, TOption>> {- _popover?: any;+> extends Component<SelectProps<TValue, TOption>, SelectState> {selectButtonRef: RefObject<any>;_getValues: () => TValue[];_getValuesSet: () => Set<TValue>;@@ -138,6 +139,9 @@ class BaseSelect<this._getValues = () => _getValues(this.props);this._getValuesSet = () => _getValuesSet(this.props);this.selectButtonRef = createRef();+ this.state = {+ isPopoverOpen: props.isInitiallyOpen || false,+ };}_getSections(): SelectSection<TOption>[] {@@ -192,8 +196,8 @@ class BaseSelect<}onChange?.({ target: { name, value } });if (!multiple) {- this._popover?.close();- this.handleClose();+ this.closePopover();+ this.restoreTriggerFocus();}};@@ -227,7 +231,7 @@ class BaseSelect<return <span style={{ minWidth: MIN_ICON_WIDTH }} />;};- handleClose = () => {+ restoreTriggerFocus = () => {// Focusing in the next tick prevents it is from reopening// when closed by selecting an item with EntersetTimeout(() => {@@ -235,6 +239,28 @@ class BaseSelect<}, 0);};+ closePopover = () => {+ this.setState({ isPopoverOpen: false });+ };++ togglePopover = (event: React.MouseEvent<HTMLAnchorElement>) => {+ event.preventDefault();+ if (!this.props.disabled) {+ this.setState(({ isPopoverOpen }) => {+ if (isPopoverOpen) {+ this.restoreTriggerFocus();+ }+ return { isPopoverOpen: !isPopoverOpen };+ });+ }+ };++ handlePopoverDismiss = () => {+ this.props.onClose?.();+ this.closePopover();+ this.restoreTriggerFocus();+ };+render() {const {buttonProps,@@ -243,13 +269,12 @@ class BaseSelect<placeholder,searchProp,searchPlaceholder,- isInitiallyOpen,- onClose,disabled,width,footer,"data-testid": testId,} = this.props;+ const { isPopoverOpen } = this.state;const sections = this._getSections();const selectedNames = sections.map((section) =>@@ -262,68 +287,78 @@ class BaseSelect<.flat().filter((n) => n);- return (- <PopoverWithTrigger- ref={(ref) => (this._popover = ref)}- triggerElement={- this.props.triggerElement || (- <SelectButton- ref={this.selectButtonRef}- hasValue={selectedNames.length > 0}- disabled={disabled}- {...buttonProps}- className={CS.flexFull}- >- {this.props.buttonText- ? this.props.buttonText- : selectedNames.length > 0- ? selectedNames.map((name, index) => (- <span key={index}>- {name}- {index < selectedNames.length - 1 ? ", " : ""}- </span>- ))- : placeholder}- </SelectButton>- )- }- onClose={composeEventHandlers(onClose, this.handleClose)}- triggerClasses={cx(CS.flex, className)}- isInitiallyOpen={isInitiallyOpen}- containerClassName={containerClassName}+ const triggerElement: ReactNode = this.props.triggerElement || (+ <SelectButton+ ref={this.selectButtonRef}+ hasValue={selectedNames.length > 0}disabled={disabled}- verticalAttachments={["top", "bottom"]}- // keep the popover from jumping around one its been opened,- // this can happen when filtering items via search- pinInitialAttachment+ {...buttonProps}+ className={CS.flexFull}>- <AccordionList<TOption>- hasInitialFocus- sections={sections}- className="MB-Select"- alwaysExpanded- width={width}- role="listbox"- itemIsSelected={this.itemIsSelected}- itemIsClickable={this.itemIsClickable}- renderItemName={this.props.optionNameFn}- getItemClassName={this.props.optionClassNameFn}- getItemStyles={this.props.optionStylesFn}- renderItemDescription={this.props.optionDescriptionFn}- renderItemIcon={this.renderItemIcon}- onChange={this.handleChange}- searchable={!!searchProp}- searchProp={searchProp}- searchPlaceholder={searchPlaceholder}- globalSearch={this.props.globalSearch}- data-testid={testId ? `${testId}-list` : null}- style={{- color: "var(--mb-color-brand)",- outline: "none",- }}- />- {footer}- </PopoverWithTrigger>+ {this.props.buttonText+ ? this.props.buttonText+ : selectedNames.length > 0+ ? selectedNames.map((name, index) => (+ <span key={index}>+ {name}+ {index < selectedNames.length - 1 ? ", " : ""}+ </span>+ ))+ : placeholder}+ </SelectButton>+ );++ return (+ <Popover+ opened={isPopoverOpen}+ onDismiss={this.handlePopoverDismiss}+ position="bottom-start"+ offset={5}+ >+ <Popover.Target>+ <a+ onClick={this.togglePopover}+ className={cx(CS.flex, className, CS.noDecoration, {+ [CS.cursorInherit]: disabled,+ })}+ aria-disabled={disabled}+ >+ {triggerElement}+ </a>+ </Popover.Target>+ <Popover.Dropdown+ className={containerClassName}+ p={0}+ data-testid="popover"+ >+ <AccordionList<TOption>+ hasInitialFocus+ sections={sections}+ className="MB-Select"+ alwaysExpanded+ width={width}+ role="listbox"+ itemIsSelected={this.itemIsSelected}+ itemIsClickable={this.itemIsClickable}+ renderItemName={this.props.optionNameFn}+ getItemClassName={this.props.optionClassNameFn}+ getItemStyles={this.props.optionStylesFn}+ renderItemDescription={this.props.optionDescriptionFn}+ renderItemIcon={this.renderItemIcon}+ onChange={this.handleChange}+ searchable={!!searchProp}+ searchProp={searchProp}+ searchPlaceholder={searchPlaceholder}+ globalSearch={this.props.globalSearch}+ data-testid={testId ? `${testId}-list` : null}+ style={{+ color: "var(--mb-color-brand)",+ outline: "none",+ }}+ />+ {footer}+ </Popover.Dropdown>+ </Popover>);}}diff --git a/frontend/src/metabase/common/components/Triggerable/Triggerable.jsx b/frontend/src/metabase/common/components/Triggerable/Triggerable.jsxdeleted file mode 100644index c45dddfc493..00000000000--- a/frontend/src/metabase/common/components/Triggerable/Triggerable.jsx+++ /dev/null@@ -1,193 +0,0 @@-/* eslint-disable react/prop-types */-// eslint-disable-next-line no-restricted-imports-import styled from "@emotion/styled";-import cx from "classnames";-import { Children, Component, cloneElement, createRef } from "react";--import CS from "metabase/css/core/index.css";-import { isObscured } from "metabase/lib/dom";-import { Tooltip } from "metabase/ui";--const Trigger = styled.a``;--/**- * higher order component that takes a component which takes props "isOpen" and optionally "onClose"- * and returns a component that renders a <a> element "trigger", and tracks whether that component is open or not- *- * @deprecated HOCs are deprecated - use Modal + useState- */-const TriggerableInner = (ComposedComponent) =>- class extends Component {- static displayName =- "Triggerable[" +- (ComposedComponent.displayName || ComposedComponent.name) +- "]";-- constructor(props, context) {- super(props, context);-- this.state = {- isOpen: props.isInitiallyOpen || false,- };-- this._startCheckObscured = this._startCheckObscured.bind(this);- this._stopCheckObscured = this._stopCheckObscured.bind(this);- this.onClose = this.onClose.bind(this);- this.trigger = createRef();- }-- static defaultProps = {- as: "a",- closeOnObscuredTrigger: false,- };-- open = () => {- this.toggle(true);- };-- close = () => {- this.toggle(false);- };-- toggle = (isOpen = !this.state.isOpen) => {- this.setState({ isOpen });- };-- onClose(e) {- // don't close if clicked the actual trigger, it will toggle- if (e && e.target && this.trigger.current.contains(e.target)) {- return;- }-- if (this.props.onClose) {- this.props.onClose(e);- }-- this.close();- }-- target() {- if (this.props.target) {- return this.props.target();- } else {- return this.trigger.current;- }- }-- componentDidMount() {- this.componentDidUpdate();- }-- componentDidUpdate() {- if (this.state.isOpen && this.props.closeOnObscuredTrigger) {- this._startCheckObscured();- } else {- this._stopCheckObscured();- }- }-- componentWillUnmount() {- this._stopCheckObscured();- }-- _startCheckObscured() {- if (this._offscreenTimer == null) {- this._offscreenTimer = setInterval(() => {- const trigger = this.trigger.current;- if (isObscured(trigger)) {- this.close();- }- }, 250);- }- }-- _stopCheckObscured() {- if (this._offscreenTimer != null) {- clearInterval(this._offscreenTimer);- this._offscreenTimer = null;- }- }-- render() {- const {- as,- triggerId,- triggerClasses,- triggerStyle,- triggerClassesOpen,- triggerClassesClose,- } = this.props;-- const isOpen =- this.props.isOpen != null ? this.props.isOpen : this.state.isOpen;-- let { triggerElement } = this.props;- if (triggerElement && triggerElement.type === Tooltip) {- // Disables tooltip when open:- triggerElement = cloneElement(triggerElement, {- disabled: !triggerElement.props.isEnabled || isOpen,- });- }-- let { children } = this.props;- if (typeof children === "function" && isOpen) {- // if children is a render prop, pass onClose to it- children = children({ onClose: this.onClose });- } else if (- Children.count(children) === 1 &&- Children.only(children).props.onClose === undefined &&- typeof Children.only(children).type !== "string"- ) {- // if we have a single child which isn't an HTML element and doesn't have an onClose prop go ahead and inject it directly- children = cloneElement(children, { onClose: this.onClose });- }-- return (- <>- <Trigger- as={as}- id={triggerId}- ref={this.trigger}- onClick={(event) => {- event.preventDefault();- !this.props.disabled && this.toggle();- }}- className={cx(- triggerClasses,- isOpen && triggerClassesOpen,- !isOpen && triggerClassesClose,- CS.noDecoration,- {- [CS.cursorInherit]: this.props.disabled,- },- )}- aria-disabled={this.props.disabled}- style={triggerStyle}- >- {typeof triggerElement === "function"- ? triggerElement({- isTriggeredComponentOpen: isOpen,- open: this.open,- close: this.close,- })- : triggerElement}- </Trigger>- {isOpen && (- <ComposedComponent- {...this.props}- isOpen={isOpen}- onClose={this.onClose}- target={() => this.target()}- sizeToFit- >- {children}- </ComposedComponent>- )}- </>- );- }- };--export const Triggerable = Object.assign(TriggerableInner, {- Trigger,-});diff --git a/frontend/src/metabase/common/components/Triggerable/index.tsx b/frontend/src/metabase/common/components/Triggerable/index.tsxdeleted file mode 100644index a5bbb31874c..00000000000--- a/frontend/src/metabase/common/components/Triggerable/index.tsx+++ /dev/null@@ -1 +0,0 @@-export { Triggerable } from "./Triggerable";diff --git a/frontend/src/metabase/common/hooks/index.ts b/frontend/src/metabase/common/hooks/index.tsindex fa91bb48e5d..0205e4a404a 100644--- a/frontend/src/metabase/common/hooks/index.ts+++ b/frontend/src/metabase/common/hooks/index.ts@@ -11,6 +11,7 @@ export * from "./use-temporary-state";export * from "./use-toast";export * from "./use-url-with-utm";export { useStoreUrl } from "./use-store-url/use-store-url";+export * from "./use-capture-event";export * from "./use-progressive-loader";export * from "./use-snapshot-selector";export * from "./use-subscriber";diff --git a/frontend/src/metabase/common/hooks/use-capture-event.ts b/frontend/src/metabase/common/hooks/use-capture-event.tsnew file mode 100644index 00000000000..69aff317b1c--- /dev/null+++ b/frontend/src/metabase/common/hooks/use-capture-event.ts@@ -0,0 +1,41 @@+import { useEffect } from "react";+import { useLatest } from "react-use";++type EventType = keyof DocumentEventMap;++type Options = {+ enabled?: boolean;+};++/**+ * Captures an event at the document level during the capture phase.+ * Useful for intercepting events before they reach other handlers,+ * e.g. closing a nested popover before the parent modal.+ *+ * Call `e.stopImmediatePropagation()` in your handler to prevent+ * other listeners from receiving the event.+ */+export function useCaptureEvent<T extends EventType>(+ eventType: T,+ handler: (event: DocumentEventMap[T]) => void,+ { enabled = true }: Options = {},+) {+ const handlerRef = useLatest(handler);++ useEffect(() => {+ if (!enabled) {+ return;+ }++ const controller = new AbortController();+ const listener = (e: DocumentEventMap[T]) => {+ handlerRef.current(e);+ };++ document.addEventListener(eventType, listener, {+ capture: true,+ signal: controller.signal,+ });+ return () => controller.abort();+ }, [enabled, eventType, handlerRef]);+}diff --git a/frontend/src/metabase/query_builder/components/NativeQueryEditor/RightClickPopover/RightClickPopover.tsx b/frontend/src/metabase/query_builder/components/NativeQueryEditor/RightClickPopover/RightClickPopover.tsxindex 6776fa0a787..8e28e177f18 100644--- a/frontend/src/metabase/query_builder/components/NativeQueryEditor/RightClickPopover/RightClickPopover.tsx+++ b/frontend/src/metabase/query_builder/components/NativeQueryEditor/RightClickPopover/RightClickPopover.tsx@@ -1,7 +1,7 @@+import { useCallback, useLayoutEffect, useState } from "react";import { t } from "ttag";-import { Popover } from "metabase/common/components/Popover";-import { Flex, Icon } from "metabase/ui";+import { Flex, Icon, Popover } from "metabase/ui";import RightClickPopoverS from "./RightClickPopover.module.css";@@ -19,24 +19,76 @@ export const RightClickPopover = ({runQuery,openSnippetModalWithSelectedText,canSaveSnippets,-}: RightClickPopoverProps) => (- <Popover isOpen={isOpen} target={target}>- <Flex direction="column">- {runQuery && (- <a className={RightClickPopoverS.Anchor} onClick={runQuery}>- <Icon mr="sm" name="play" size={16} />- <h4>{t`Run selection`}</h4>- </a>- )}- {canSaveSnippets && openSnippetModalWithSelectedText && (- <a- className={RightClickPopoverS.Anchor}- onClick={openSnippetModalWithSelectedText}- >- <Icon mr="sm" name="snippet" size={16} />- <h4>{t`Save as snippet`}</h4>- </a>- )}- </Flex>- </Popover>-);+}: RightClickPopoverProps) => {+ const [position, setPosition] = useState<DOMRect | null>(null);++ useLayoutEffect(() => {+ if (!isOpen) {+ setPosition(null);+ return;+ }++ const updatePosition = () => {+ const element = target();+ if (element) {+ setPosition(element.getBoundingClientRect());+ }+ };++ updatePosition();++ // Update position on scroll/resize+ window.addEventListener("scroll", updatePosition, true);+ window.addEventListener("resize", updatePosition);++ return () => {+ window.removeEventListener("scroll", updatePosition, true);+ window.removeEventListener("resize", updatePosition);+ };+ }, [isOpen, target]);++ const setAnchorRef = useCallback(+ (node: HTMLDivElement | null) => {+ if (node && position) {+ node.style.position = "fixed";+ node.style.left = `${position.left}px`;+ node.style.top = `${position.bottom}px`;+ node.style.width = `${position.width}px`;+ node.style.height = "0";+ node.style.pointerEvents = "none";+ }+ },+ [position],+ );++ if (!isOpen || !position) {+ return null;+ }++ return (+ <Popover opened position="bottom-start">+ <Popover.Target>+ <div ref={setAnchorRef} />+ </Popover.Target>+ <Popover.Dropdown data-testid="popover">+ <Flex direction="column">+ {runQuery && (+ <a className={RightClickPopoverS.Anchor} onClick={runQuery}>+ <Icon mr="sm" name="play" size={16} />+ <h4>{t`Run selection`}</h4>+ </a>+ )}+ {canSaveSnippets && openSnippetModalWithSelectedText && (+ <a+ className={RightClickPopoverS.Anchor}+ onClick={openSnippetModalWithSelectedText}+ >+ <Icon mr="sm" name="snippet" size={16} />+ <h4>{t`Save as snippet`}</h4>+ </a>+ )}+ </Flex>+ </Popover.Dropdown>+ </Popover>+ );+};diff --git a/frontend/src/metabase/search/components/DropdownSidebarFilter/DropdownSidebarFilter.tsx b/frontend/src/metabase/search/components/DropdownSidebarFilter/DropdownSidebarFilter.tsxindex c947ca9f865..d8a6f571871 100644--- a/frontend/src/metabase/search/components/DropdownSidebarFilter/DropdownSidebarFilter.tsx+++ b/frontend/src/metabase/search/components/DropdownSidebarFilter/DropdownSidebarFilter.tsx@@ -2,7 +2,7 @@ import type { MouseEvent } from "react";import { useLayoutEffect, useRef, useState } from "react";import { isEmpty } from "underscore";-import { Popover } from "metabase/common/components/Popover";+import { useCaptureEvent } from "metabase/common/hooks";import { useIsSmallScreen } from "metabase/common/hooks/use-is-small-screen";import { useSelector } from "metabase/lib/redux";import { isNotNull } from "metabase/lib/types";@@ -14,7 +14,7 @@ import type {} from "metabase/search/types";import { getIsNavbarOpen } from "metabase/selectors/app";import type { IconName } from "metabase/ui";-import { Box, Button, Center, Icon, Stack, Text } from "metabase/ui";+import { Box, Button, Center, Icon, Popover, Stack, Text } from "metabase/ui";import {DropdownFieldSet,@@ -25,6 +25,8 @@ import {export type DropdownSidebarFilterProps<T extends FilterTypeKeys = any> = {filter: SearchFilterDropdown<T>;+ isOpen: boolean;+ onOpenChange: (isOpen: boolean) => void;} & SearchFilterComponentProps<T>;export const DropdownSidebarFilter = ({@@ -32,9 +34,9 @@ export const DropdownSidebarFilter = ({"data-testid": dataTestId,value,onChange,+ isOpen: isPopoverOpen,+ onOpenChange,}: DropdownSidebarFilterProps) => {- const [isPopoverOpen, setIsPopoverOpen] = useState(false);-const isNavbarOpen = useSelector(getIsNavbarOpen);const isSmallScreen = useIsSmallScreen();@@ -62,27 +64,23 @@ export const DropdownSidebarFilter = ({useLayoutEffect(() => {if (isNavbarOpen && isSmallScreen) {- setIsPopoverOpen(false);+ onOpenChange(false);}- }, [isNavbarOpen, isSmallScreen]);+ }, [isNavbarOpen, isSmallScreen, onOpenChange]);const onApplyFilter = (value: SearchFilterPropTypes) => {onChange(value);- setIsPopoverOpen(false);+ onOpenChange(false);};const onClearFilter = (e: MouseEvent) => {if (fieldHasValue) {e.stopPropagation();onChange(null);- setIsPopoverOpen(false);+ onOpenChange(false);}};- const onPopoverClose = () => {- setIsPopoverOpen(false);- };-const getDropdownIcon = (): IconName => {if (fieldHasValue) {return "close";@@ -91,72 +89,78 @@ export const DropdownSidebarFilter = ({}};+ useCaptureEvent(+ "keydown",+ (e) => {+ if (e.key === "Escape") {+ e.stopImmediatePropagation();+ onOpenChange(false);+ }+ },+ { enabled: isPopoverOpen },+ );+return (- <Box- data-testid={dataTestId}- ref={dropdownRef}- onClick={() => setIsPopoverOpen(!isPopoverOpen)}- w="100%"- mt={fieldHasValue ? "0.25rem" : 0}+ <Popover+ opened={isPopoverOpen}+ onChange={onOpenChange}+ position="bottom-end">- <DropdownFieldSet- noPadding- legend={fieldHasValue ? label() : undefined}- fieldHasValueOrFocus={fieldHasValue}- >- <GroupOverflowHidden justify="space-between" wrap="nowrap" w="100%">- {fieldHasValue ? (- <DisplayComponent value={value} />- ) : (- <GroupOverflowHidden wrap="nowrap">- {iconName && <DropdownLabelIcon size={16} name={iconName} />}- <Text fw={700} truncate>- {label()}- </Text>+ <Popover.Target>+ <Box+ data-testid={dataTestId}+ ref={dropdownRef}+ onClick={() => onOpenChange(!isPopoverOpen)}+ w="100%"+ mt={fieldHasValue ? "0.25rem" : 0}+ >+ <DropdownFieldSet+ noPadding+ legend={fieldHasValue ? label() : undefined}+ fieldHasValueOrFocus={fieldHasValue}+ >+ <GroupOverflowHidden justify="space-between" wrap="nowrap" w="100%">+ {fieldHasValue ? (+ <DisplayComponent value={value} />+ ) : (+ <GroupOverflowHidden wrap="nowrap">+ {iconName && <DropdownLabelIcon size={16} name={iconName} />}+ <Text fw={700} truncate>+ {label()}+ </Text>+ </GroupOverflowHidden>+ )}+ <Button+ data-testid="sidebar-filter-dropdown-button"+ size="compact-xs"+ mr="0.25rem"+ c="inherit"+ variant="subtle"+ onClick={onClearFilter}+ leftSection={+ <Center m="-0.25rem">+ <Icon size={16} name={getDropdownIcon()} />+ </Center>+ }+ /></GroupOverflowHidden>+ </DropdownFieldSet>+ </Box>+ </Popover.Target>++ <Popover.Dropdown data-testid="popover">+ <SearchEventSandbox>+ {popoverWidth && (+ <Stack mah="50vh">+ <ContentComponent+ value={value}+ onChange={(selected) => onApplyFilter(selected)}+ width={popoverWidth}+ />+ </Stack>)}- <Button- data-testid="sidebar-filter-dropdown-button"- size="compact-xs"- mr="0.25rem"- c="inherit"- variant="subtle"- onClick={onClearFilter}- leftSection={- <Center m="-0.25rem">- <Icon size={16} name={getDropdownIcon()} />- </Center>- }- />- </GroupOverflowHidden>- </DropdownFieldSet>-- <Popover- isOpen={isPopoverOpen}- onClose={onPopoverClose}- target={dropdownRef.current}- ignoreTrigger- autoWidth- sizeToFit- pinInitialAttachment- horizontalAttachments={["right"]}- >- {({ maxHeight }: { maxHeight: number }) =>- popoverWidth && (- <SearchEventSandbox>- {popoverWidth && (- <Stack mah={maxHeight}>- <ContentComponent- value={value}- onChange={(selected) => onApplyFilter(selected)}- width={popoverWidth}- />- </Stack>- )}- </SearchEventSandbox>- )- }- </Popover>- </Box>+ </SearchEventSandbox>+ </Popover.Dropdown>+ </Popover>);};diff --git a/frontend/src/metabase/search/components/DropdownSidebarFilter/DropdownSidebarFilter.unit.spec.tsx b/frontend/src/metabase/search/components/DropdownSidebarFilter/DropdownSidebarFilter.unit.spec.tsxindex aa882584456..6f32eb1b749 100644--- a/frontend/src/metabase/search/components/DropdownSidebarFilter/DropdownSidebarFilter.unit.spec.tsx+++ b/frontend/src/metabase/search/components/DropdownSidebarFilter/DropdownSidebarFilter.unit.spec.tsx@@ -37,18 +37,31 @@ const MockSearchSidebarFilter = ({filter,value,onChange,+ isOpen: initialIsOpen,+ onOpenChange,+ "data-testid": dataTestId,}: DropdownSidebarFilterProps) => {const [selectedValues, setSelectedValues] = useState(value);+ const [isOpen, setIsOpen] = useState(initialIsOpen);+const onFilterChange = (elem: DropdownSidebarFilterProps["value"]) => {setSelectedValues(elem);onChange(elem);};+ const handleOpenChange = (nextIsOpen: boolean) => {+ setIsOpen(nextIsOpen);+ onOpenChange(nextIsOpen);+ };+return (<DropdownSidebarFilterfilter={filter}+ data-testid={dataTestId}value={selectedValues}onChange={onFilterChange}+ isOpen={isOpen}+ onOpenChange={handleOpenChange}/>);};@@ -58,6 +71,8 @@ const setup = (options: Partial<DropdownSidebarFilterProps> = {}) => {filter: mockFilter,value: [],onChange: jest.fn(),+ isOpen: false,+ onOpenChange: jest.fn(),};const props: DropdownSidebarFilterProps = { ...defaultProps, ...options };diff --git a/frontend/src/metabase/search/components/SearchSidebar/SearchSidebar.tsx b/frontend/src/metabase/search/components/SearchSidebar/SearchSidebar.tsxindex 976331f0678..56139e0175a 100644--- a/frontend/src/metabase/search/components/SearchSidebar/SearchSidebar.tsx+++ b/frontend/src/metabase/search/components/SearchSidebar/SearchSidebar.tsx@@ -1,3 +1,4 @@+import { useState } from "react";import _ from "underscore";import { useShowOtherUsersCollections } from "metabase/common/hooks/use-show-other-users-collections";@@ -27,6 +28,10 @@ type SearchSidebarProps = {};export const SearchSidebar = ({ value, onChange }: SearchSidebarProps) => {+ const [openFilterKey, setOpenFilterKey] = useState<FilterTypeKeys | null>(+ null,+ );+const filterMap: Record<FilterTypeKeys, SearchFilterComponent> = {[SearchFilterKeys.Type]: TypeFilter,[SearchFilterKeys.CreatedBy]: CreatedByFilter,@@ -75,6 +80,16 @@ export const SearchSidebar = ({ value, onChange }: SearchSidebarProps) => {data-testid={`${key}-search-filter`}value={filterValue}onChange={(value) => onOutputChange(key, Filter.toUrl(value))}+ isOpen={openFilterKey === key}+ onOpenChange={(isOpen) => {+ if (isOpen) {+ setOpenFilterKey(key);+ } else if (openFilterKey === key) {+ // Only close if this filter is still the one that's open+ // This prevents race condition when clicking another filter+ setOpenFilterKey(null);+ }+ }}/>);}diff --git a/frontend/src/metabase/visualizations/components/ChartSettingsWidget.tsx b/frontend/src/metabase/visualizations/components/ChartSettingsWidget.tsxindex 609710239f8..c4f16cf8814 100644--- a/frontend/src/metabase/visualizations/components/ChartSettingsWidget.tsx+++ b/frontend/src/metabase/visualizations/components/ChartSettingsWidget.tsx@@ -1,7 +1,6 @@import cx from "classnames";import type { CSSProperties, ComponentType } from "react";-import PopoverS from "metabase/common/components/Popover/Popover.module.css";import FormS from "metabase/css/components/form.module.css";import { Box, Group, Icon, Text, Tooltip } from "metabase/ui";@@ -43,7 +42,6 @@ const ChartSettingsWidget = ({hidden={hidden}className={cx({[FormS.FormField]: isFormField,- [PopoverS.FormField]: isFormField,})}inline={inline}data-testid={dataTestId ?? `chart-settings-widget-${extraWidgetProps.id}`}diff --git a/frontend/src/metabase/visualizations/components/settings/ChartSettingFieldPicker.styled.tsx b/frontend/src/metabase/visualizations/components/settings/ChartSettingFieldPicker.styled.tsxindex 4ea42786dcd..a5bbcd223ce 100644--- a/frontend/src/metabase/visualizations/components/settings/ChartSettingFieldPicker.styled.tsx+++ b/frontend/src/metabase/visualizations/components/settings/ChartSettingFieldPicker.styled.tsx@@ -2,7 +2,6 @@ import isPropValid from "@emotion/is-prop-valid";// eslint-disable-next-line no-restricted-importsimport styled from "@emotion/styled";-import { Triggerable } from "metabase/common/components/Triggerable";import { Group, Icon } from "metabase/ui";export const GrabberHandle = styled(Icon, { shouldForwardProp: isPropValid })`@@ -16,10 +15,6 @@ export const ChartSettingFieldPickerRoot = styled(Group, {border: 1px solid var(--mb-color-border);border-radius: ${({ theme }) => theme.radius.md};overflow: hidden;- ${Triggerable.Trigger} {- flex: 1;- overflow: hidden;- }&:hover {${GrabberHandle} {diff --git a/frontend/src/metabase/visualizations/components/skeletons/ChartSkeleton/ChartSkeleton.unit.spec.tsx b/frontend/src/metabase/visualizations/components/skeletons/ChartSkeleton/ChartSkeleton.unit.spec.tsxindex ea891ac351f..1586d7c69c0 100644--- a/frontend/src/metabase/visualizations/components/skeletons/ChartSkeleton/ChartSkeleton.unit.spec.tsx+++ b/frontend/src/metabase/visualizations/components/skeletons/ChartSkeleton/ChartSkeleton.unit.spec.tsx@@ -63,10 +63,6 @@ const setup = ({};describe("ChartSkeleton", () => {- beforeAll(() => {- jest.unmock("metabase/common/components/Popover");- });-displayTestData.forEach(({ name, display }) => {const displayDescription = `${name} description`;