feat: enhance CategoryAutocomplete and AddFeatureDialog components

- Added responsive width handling to the CategoryAutocomplete component, ensuring the popover adjusts based on the trigger button's width.
- Updated the AddFeatureDialog button width from 180px to 200px for improved layout consistency.
This commit is contained in:
Kacper
2025-12-16 14:49:23 +01:00
parent 2ee4ec65b4
commit f86bb3eab8
2 changed files with 29 additions and 2 deletions

View File

@@ -39,11 +39,33 @@ export function CategoryAutocomplete({
"data-testid": testId, "data-testid": testId,
}: CategoryAutocompleteProps) { }: CategoryAutocompleteProps) {
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false);
const [triggerWidth, setTriggerWidth] = React.useState<number>(0);
const triggerRef = React.useRef<HTMLButtonElement>(null);
// Update trigger width when component mounts or value changes
React.useEffect(() => {
if (triggerRef.current) {
const updateWidth = () => {
setTriggerWidth(triggerRef.current?.offsetWidth || 0);
};
updateWidth();
// Listen for resize events to handle responsive behavior
const resizeObserver = new ResizeObserver(updateWidth);
resizeObserver.observe(triggerRef.current);
return () => {
resizeObserver.disconnect();
};
}
}, [value]);
return ( return (
<Popover open={open} onOpenChange={setOpen}> <Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild> <PopoverTrigger asChild>
<Button <Button
ref={triggerRef}
variant="outline" variant="outline"
role="combobox" role="combobox"
aria-expanded={open} aria-expanded={open}
@@ -57,7 +79,12 @@ export function CategoryAutocomplete({
<ChevronsUpDown className="opacity-50" /> <ChevronsUpDown className="opacity-50" />
</Button> </Button>
</PopoverTrigger> </PopoverTrigger>
<PopoverContent className="w-[200px] p-0"> <PopoverContent
className="p-0"
style={{
width: Math.max(triggerWidth, 200),
}}
>
<Command> <Command>
<CommandInput placeholder="Search category..." className="h-9" /> <CommandInput placeholder="Search category..." className="h-9" />
<CommandList> <CommandList>

View File

@@ -273,7 +273,7 @@ export function AddFeatureDialog({
<div className="flex w-fit items-center gap-3 select-none cursor-default"> <div className="flex w-fit items-center gap-3 select-none cursor-default">
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
<Button variant="outline" size="sm" className="w-[180px] justify-between"> <Button variant="outline" size="sm" className="w-[200px] justify-between">
{enhancementMode === 'improve' && 'Improve Clarity'} {enhancementMode === 'improve' && 'Improve Clarity'}
{enhancementMode === 'technical' && 'Add Technical Details'} {enhancementMode === 'technical' && 'Add Technical Details'}
{enhancementMode === 'simplify' && 'Simplify'} {enhancementMode === 'simplify' && 'Simplify'}