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

Fix(web-react): Closing Modal by Escape key #1206

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 9 additions & 3 deletions packages/web-react/src/hooks/useCancelEvent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { useCallback, useEffect, MutableRefObject } from 'react';

const EVENT_CANCEL = 'cancel';
import { MutableRefObject, useCallback, useEffect } from 'react';

/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/cancel_event
* @see https://jira.lmc.cz/browse/DS-1108
* Here should be used `cancel` event instead of `close` event.
* But when dialog is closed using `escape` key, `cancel` event is not fired.
*/
const EVENT_CANCEL = 'close';

Copy link
Contributor

@pavelklibani pavelklibani Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at this option to change cancel for close, but now if you close modal with close button on with backdrop click onClose method is called twice - from button/backdrop and from close event. Are we ok with that?

export const useCancelEvent = (ref: MutableRefObject<HTMLElement | null>, callback: (event: Event) => void) => {
const handleCancel = useCallback(
Expand Down
Loading