import React from "react"; import { Classes as BlueprintClasses, InputGroupProps } from "@blueprintjs/core"; import { Select as BlueprintSelect, SelectProps as BlueprintSelectProps } from "@blueprintjs/select"; import { CLASSPREFIX as eccgui } from "../../configuration/constants"; import { Button, ButtonProps } from "../Button/Button"; import { ContextOverlayProps } from "../ContextOverlay"; import Icon from "../Icon/Icon"; import { TestableComponent } from "../interfaces"; import OverflowText from "../Typography/OverflowText"; export interface SelectProps extends TestableComponent, Omit, "popoverTargetProps" | "popoverContentProps" | "popoverProps" | "popoverRef">, Pick { /** * Textual representation of the the selected value. * This is displayed if the select target is not controlled directly via `children` elements. */ text?: string; /** * Placeholder text displayed for selects without defined `text`. * This is displayed if the select target is not controlled directly via `children` elements. */ placeholder?: string; /** * Props to spread to `ContextOverlay` that is used to display the dropdown. */ contextOverlayProps?: Partial< Omit >; /** * Event handler to reset search input. * Only works with the uncontrolled default select target. * If set then `rightElement` is automatically set with an action button to trigger the handler. */ onClearanceHandler?: () => void; /** * Tooltip to show for the clear button. * Only works with the uncontrolled default select target. */ onClearanceText?: string; /** * If set then a `div` element is used as wrapper. * It uses the attributes given via this property. */ wrapperProps?: React.HTMLAttributes; } /** * Create a Select box without the HTML select element. * It is possible to filter options, as well as to add new options if necessary. * * **Use this input element when the value is primarily selected from a defined set of elements.** */ export function Select({ contextOverlayProps, className, children, text, placeholder = "Select item ...", icon, rightIcon, onClearanceHandler, inputProps, onClearanceText = "Reset selection", "data-test-id": dataTestId, "data-testid": dataTestid, wrapperProps, ...otherSelectProps }: SelectProps) { const selectContent = ( popoverProps={ { minimal: true, matchTargetWidth: otherSelectProps.fill ?? false, ...contextOverlayProps, } as ContextOverlayProps } popoverContentProps={ { "data-test-id": dataTestId ? dataTestId + "_drowpdown" : undefined, "data-testid": dataTestid ? dataTestid + "_dropdown" : undefined, } as BlueprintSelectProps["popoverContentProps"] } inputProps={ { round: true, fill: otherSelectProps.fill, "data-test-id": dataTestId ? dataTestId + "_searchinput" : undefined, "data-testid": dataTestid ? dataTestid + "_searchinput" : undefined, ...inputProps, } as InputGroupProps } className={`${eccgui}-select` + (className ? ` ${className}` : "")} {...otherSelectProps} > {children ?? (