ui icon indicating copy to clipboard operation
ui copied to clipboard

Custom onOpenChange in Drawer doesn't work.

Open MohammadHarisZia-ell opened this issue 1 year ago • 1 comments

const [open, setOpen] = React.useState(false); const onOpenChange = () => { console.log("inside", open); setOpen(!open); };

<Drawer open={open} onOpenChange={onOpenChange}>

On Click Logs:

index.tsx:169 inside true index.tsx:169 inside false index.tsx:169 inside true index.tsx:169 inside false index.tsx:169 inside true index.tsx:169 inside false index.tsx:169 inside true index.tsx:169 inside false index.tsx:169 inside true index.tsx:169 inside false index.tsx:169 inside true index.tsx:169 inside false

MohammadHarisZia-ell avatar Jan 15 '24 18:01 MohammadHarisZia-ell

@MohammadHarisZia-ell

You should modify the onOpenChange event-listener to this

const [open, setOpen] = React.useState(false); const onOpenChange = (val) => { console.log("inside", val); setOpen(val); };

export function NewPost() {
	const [open, setOpen] = useState(false);

	function handleOpenChange(val: boolean) {
		console.log('Inside', val);
		setOpen(val);
	}

	return (
		<Drawer open={open} onOpenChange={handleOpenChange}>
			<DrawerTrigger asChild>
				<Button variant='outline'>NEW POST</Button>
			</DrawerTrigger>
			<DrawerContent>
				<div className='mx-auto w-full max-w-sm'>
					<DrawerHeader>
						<DrawerTitle>
							Title
							<Textarea placeholder='Title' />
						</DrawerTitle>
						<h1>Languages</h1>
						<p>Demo</p>
						<DrawerDescription>
							<Textarea placeholder='Description...' />
						</DrawerDescription>
					</DrawerHeader>
				</div>
			</DrawerContent>
		</Drawer>
	);
}
}

https://github.com/shadcn-ui/ui/assets/150527559/49d77bb2-40bb-42d0-afd4-1c89a680acc6

imopbuilder avatar Jan 21 '24 07:01 imopbuilder

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Feb 12 '24 23:02 shadcn