Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle click outside create and edit dialog #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ra-dialog-crud/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dslab/ra-dialog-crud",
"version": "1.0.2",
"version": "1.0.3",
"author": {
"name": "Claudio Ballardini",
"email": "[email protected]"
Expand Down
9 changes: 6 additions & 3 deletions packages/ra-dialog-crud/src/CreateInDialogButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const CreateInDialogButton = (props: CreateInDialogButtonProps) => {
variant,
mutationOptions = {},
sx,
closeOnClickOutside = true,
...rest
} = props;

Expand All @@ -60,8 +61,10 @@ export const CreateInDialogButton = (props: CreateInDialogButtonProps) => {
e.stopPropagation();
};

const handleDialogClose: MouseEventHandler<HTMLButtonElement> = e => {
closeDialog();
const handleDialogClose: any = (e,reason) => {
if (!reason || (closeOnClickOutside && reason =="backdropClick")){
closeDialog();
}
e.stopPropagation();
};

Expand All @@ -75,7 +78,6 @@ export const CreateInDialogButton = (props: CreateInDialogButtonProps) => {
}),
[handleDialogClose, handleDialogOpen]
);

return (
<>
<Button
Expand Down Expand Up @@ -185,6 +187,7 @@ export type CreateInDialogButtonProps<
label?: string;
variant?: 'text' | 'outlined' | 'contained';
icon?: ReactElement;
closeOnClickOutside?: boolean;
};

const PREFIX = 'RaCreateInDialogButton';
Expand Down
8 changes: 6 additions & 2 deletions packages/ra-dialog-crud/src/EditInDialogButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const EditInDialogButton = (props: EditInDialogButtonProps) => {
mutationMode = 'undoable',
sx,
emptyWhileLoading = false,
closeOnClickOutside = true,
...rest
} = props;

Expand All @@ -70,8 +71,10 @@ export const EditInDialogButton = (props: EditInDialogButtonProps) => {
e.stopPropagation();
};

const handleDialogClose: MouseEventHandler<HTMLButtonElement> = e => {
closeDialog();
const handleDialogClose: any = (e,reason) => {
if (!reason || (closeOnClickOutside && reason =="backdropClick")){
closeDialog();
}
e.stopPropagation();
};

Expand Down Expand Up @@ -247,6 +250,7 @@ export type EditInDialogButtonProps<
icon?: ReactElement;
variant?: 'text' | 'outlined' | 'contained';
emptyWhileLoading?: boolean;
closeOnClickOutside?: boolean;
};

const PREFIX = 'RaEditInDialogButton';
Expand Down
8 changes: 6 additions & 2 deletions packages/ra-dialog-crud/src/ShowInDialogButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const ShowInDialogButton = (props: ShowInDialogButtonProps) => {
sx,
emptyWhileLoading = false,
disableAuthentication,
closeOnClickOutside = true,
} = props;

const resource = useResourceContext(props);
Expand All @@ -63,8 +64,10 @@ export const ShowInDialogButton = (props: ShowInDialogButtonProps) => {
e.stopPropagation();
};

const handleDialogClose: MouseEventHandler<HTMLButtonElement> = e => {
setOpen(false);
const handleDialogClose: any = (e,reason) => {
if (!reason || (closeOnClickOutside && reason =="backdropClick")){
setOpen(false);
}
e.stopPropagation();
};

Expand Down Expand Up @@ -208,6 +211,7 @@ export type ShowInDialogButtonProps<RecordType extends RaRecord = RaRecord> =
label?: string;
variant?: 'text' | 'outlined' | 'contained';
icon?: ReactElement;
closeOnClickOutside?: boolean;
};

const PREFIX = 'RaShowInDialogButton';
Expand Down