import { ActionIcon, Tooltip } from "@mantine/core"; import { IconX } from "@tabler/icons-react"; /** * The button floats over the right end of the field it fills, so the field * has to reserve this much room for it. Exported rather than repeated, so a * size change here cannot leave a caller's text running underneath it. */ export const clearButtonWidth = 34; /** * Mantine's input border. The button is inset by it so its hover fill stays * inside the field instead of painting over its border. */ const fieldBorderWidth = 1; interface ClearFieldButtonProps { /** * Names the field in the tooltip and the accessible name, as the object of * "Clear": "the follow-up question", "the search query". One string feeds * both, so an icon-only control never says one thing on screen and another * to a screen reader. */ label: string; /** Empties the field. */ onClear: () => void; /** Distance from the field's right edge to the positioned ancestor's, in pixels. */ rightOffset?: number; disabled?: boolean; } export default function ClearFieldButton({ label, onClear, rightOffset = 0, disabled = false, }: ClearFieldButtonProps) { return ( event.preventDefault()} disabled={disabled} aria-label={label} style={{ position: "absolute", right: rightOffset + fieldBorderWidth, top: fieldBorderWidth, bottom: fieldBorderWidth, height: `calc(100% - ${2 * fieldBorderWidth}px)`, width: clearButtonWidth, ...(disabled && { backgroundColor: "transparent" }), }} > ); }