Polish filters combobox alignment
This commit is contained in:
parent
feca5dd4a7
commit
59a94744b3
2 changed files with 45 additions and 26 deletions
|
|
@ -1,9 +1,7 @@
|
|||
"use client"
|
||||
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
import { useEffect, useMemo, useState, useId, type ReactNode } from "react"
|
||||
import { ChevronsUpDown, Check, X } from "lucide-react"
|
||||
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
|
|
@ -26,6 +24,7 @@ type SearchableComboboxProps = {
|
|||
searchPlaceholder?: string
|
||||
emptyText?: string
|
||||
className?: string
|
||||
triggerClassName?: string
|
||||
disabled?: boolean
|
||||
allowClear?: boolean
|
||||
clearLabel?: string
|
||||
|
|
@ -34,6 +33,7 @@ type SearchableComboboxProps = {
|
|||
contentClassName?: string
|
||||
scrollClassName?: string
|
||||
scrollProps?: React.HTMLAttributes<HTMLDivElement>
|
||||
prefix?: ReactNode
|
||||
}
|
||||
|
||||
export function SearchableCombobox({
|
||||
|
|
@ -44,6 +44,7 @@ export function SearchableCombobox({
|
|||
searchPlaceholder = "Buscar...",
|
||||
emptyText = "Nenhuma opção encontrada.",
|
||||
className,
|
||||
triggerClassName,
|
||||
disabled,
|
||||
allowClear = false,
|
||||
clearLabel = "Limpar seleção",
|
||||
|
|
@ -52,9 +53,11 @@ export function SearchableCombobox({
|
|||
contentClassName,
|
||||
scrollClassName,
|
||||
scrollProps,
|
||||
prefix,
|
||||
}: SearchableComboboxProps) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [search, setSearch] = useState("")
|
||||
const listId = useId()
|
||||
|
||||
const selected = useMemo(() => {
|
||||
if (value === null) return null
|
||||
|
|
@ -92,24 +95,37 @@ export function SearchableCombobox({
|
|||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
<button
|
||||
type="button"
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
aria-controls={listId}
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
"flex min-h-[46px] w-full items-center justify-between rounded-full border border-input bg-background px-3 py-2.5 text-sm font-medium text-foreground shadow-sm transition focus-visible:ring-2 focus-visible:ring-ring",
|
||||
"flex h-full w-full items-center justify-between gap-2 rounded-full border border-input bg-background px-3 text-sm font-semibold text-foreground shadow-sm transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60",
|
||||
className,
|
||||
triggerClassName,
|
||||
)}
|
||||
>
|
||||
<span className="truncate text-left">
|
||||
{renderValue ? renderValue(selected) : selected?.label ?? <span className="text-muted-foreground">{placeholder}</span>}
|
||||
<span className="flex flex-1 items-center gap-2">
|
||||
{prefix ? <span className="inline-flex items-center text-neutral-400">{prefix}</span> : null}
|
||||
<span className="flex-1 truncate text-left">
|
||||
{renderValue ? (
|
||||
renderValue(selected)
|
||||
) : selected?.label ? (
|
||||
selected.label
|
||||
) : (
|
||||
<span className="text-muted-foreground">{placeholder}</span>
|
||||
)}
|
||||
</span>
|
||||
</span>
|
||||
<ChevronsUpDown className="ml-2 size-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
<ChevronsUpDown className="ml-2 size-4 shrink-0 text-neutral-500 opacity-70" />
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className={cn("z-50 w-[var(--radix-popover-trigger-width)] max-w-[480px] p-0", contentClassName)}>
|
||||
<PopoverContent
|
||||
id={listId}
|
||||
className={cn("z-50 w-[var(--radix-popover-trigger-width)] max-w-[480px] p-0", contentClassName)}
|
||||
>
|
||||
<div className="border-b border-border/80 p-2">
|
||||
<Input
|
||||
autoFocus
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue