mrzachnugent / react-native-reusables

Universal shadcn/ui for React Native featuring a focused collection of components - Crafted with NativeWind v4 and accessibility in mind.
https://rnr-docs.vercel.app
MIT License
3.25k stars 134 forks source link

[ BUG ] Dialog X button doesn't close dialog #160

Closed adnjoo closed 2 months ago

adnjoo commented 3 months ago

Describe the bug X button on top right of Dialog doesn't close Dialog

Example code

import {
  Dialog,
  ...
} from '@/src/components/ui/dialog';

...

    <Dialog open={isAddingNote}>
      <DialogTrigger asChild>
        <Button variant='outline' onPress={() => setIsAddingNote(true)}>
          <CirclePlus size={24} />
        </Button>
      </DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Add Note</DialogTitle>
          <DialogDescription>Enter your note content below:</DialogDescription>
        </DialogHeader>
        <TextInput
          value={newNoteContent}
          onChangeText={(text) => setNewNoteContent(text)}
          placeholder='Enter your note here...'
          className='mb-3 rounded-sm border border-gray-300 p-3'
        />
        <DialogFooter>
          <DialogClose asChild>
            <Button onPress={() => setIsAddingNote(false)}>
              <Text className='text-white'>Cancel</Text>
            </Button>
          </DialogClose>
          <Button onPress={handleAddNote}>
            <Text className='text-white'>Save</Text>
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>

To Reproduce Steps to reproduce the behavior:

  1. install components using CLI npx @react-native-reusables/cli@latest add dialog
  2. Open Modal
  3. Click on X button
  4. Dialog doesn't close

Expected behavior Expect modal to close

Screenshots

Screenshot 2024-06-08 at 5 18 42 PM

Platform (please complete the following information):

Additional context

I modified DialogContent to pass through handleClose to make the X button close the modal. But there are some types/linting warnings.

const DialogContent = React.forwardRef<
  React.ElementRef<typeof DialogPrimitive.Content>,
  React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & { portalHost?: string }
>(({ className, children, portalHost, handleClose, ...props }, ref) => {
  const { open } = DialogPrimitive.useRootContext();
  return (
    <DialogPortal hostName={portalHost}>
      <DialogOverlay>
        <DialogPrimitive.Content
          ref={ref}
          className={cn(
            'z-50 max-w-lg gap-4 border border-border web:cursor-default bg-background p-6 shadow-lg web:duration-200 rounded-lg',
            open
              ? 'web:animate-in web:fade-in-0 web:zoom-in-95'
              : 'web:animate-out web:fade-out-0 web:zoom-out-95',
            className
          )}
          {...props}
        >
          {children}
          <DialogPrimitive.Close
            className={
              'absolute right-4 top-4 p-0.5 web:group rounded-sm opacity-70 web:ring-offset-background web:transition-opacity web:hover:opacity-100 web:focus:outline-none web:focus:ring-2 web:focus:ring-ring web:focus:ring-offset-2 web:disabled:pointer-events-none'
            }
            onPress={handleClose}
          >
            <X
              size={Platform.OS === 'web' ? 16 : 18}
              className={cn('text-muted-foreground', open && 'text-accent-foreground')}
            />
          </DialogPrimitive.Close>
        </DialogPrimitive.Content>
      </DialogOverlay>
    </DialogPortal>
  );
});
DialogContent.displayName = DialogPrimitive.Content.displayName;
mrzachnugent commented 3 months ago

@adnjoo Unfortunately I cannot reproduce this issue. I added a "handleClose" function that logs "Pressed". It logs and the dialog closes successfully on press of the "x" button.

Can you make sure your files are up to date? If the problem persists, can you provide a minimal reproduction repo as it is the only way I could look into this?

mrzachnugent commented 2 months ago

Closing due to inactivity.

If you are still experiencing this issue, please open a new issue with a minimal reproduction repo