mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
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:
@@ -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>
|
||||||
|
|||||||
@@ -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'}
|
||||||
|
|||||||
Reference in New Issue
Block a user