Skip to content

Commit

Permalink
Merge pull request #4762 from thematters/adjust-esc-issue
Browse files Browse the repository at this point in the history
Adjust esc issue
  • Loading branch information
wlliaml authored Aug 21, 2024
2 parents 680b4c7 + 36103db commit 128abb7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/common/enums/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ export enum UNIVERSAL_AUTH_TRIGGER {
* Broadcast channel
*/
export const CHANNEL_VERIFIED_EMAIL = 'channel-verified-email'
export const ENABLE_SUSPEND_DISMISS_ON_ESC = 'enableSuspendDismissOnESC'
export const DISABLE_SUSPEND_DISMISS_ON_ESC = 'disableSuspendDismissOnESC'
33 changes: 21 additions & 12 deletions src/components/Dialog/Inner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ import classNames from 'classnames'
import _get from 'lodash/get'
import { useRef, useState } from 'react'

import { KEYVALUE } from '~/common/enums'
import {
DISABLE_SUSPEND_DISMISS_ON_ESC,
ENABLE_SUSPEND_DISMISS_ON_ESC,
KEYVALUE,
} from '~/common/enums'
import { capitalizeFirstLetter, dom } from '~/common/utils'
import { Media, useNativeEventListener, useOutsideClick } from '~/components'
import {
Media,
useEventListener,
useNativeEventListener,
useOutsideClick,
} from '~/components'

import Handle from '../Handle'
import styles from './styles.module.css'
Expand Down Expand Up @@ -48,7 +57,15 @@ const Inner: React.FC<
children,
}) => {
const node: React.RefObject<any> | null = useRef(null)
const [compositioning, setCompositioning] = useState(false)
const [suspendDismissOnESC, setSuspendDismissOnESC] = useState(false)

useEventListener(ENABLE_SUSPEND_DISMISS_ON_ESC, () => {
setSuspendDismissOnESC(true)
})

useEventListener(DISABLE_SUSPEND_DISMISS_ON_ESC, () => {
setSuspendDismissOnESC(false)
})

const innerClasses = classNames({
[styles.inner]: true,
Expand Down Expand Up @@ -100,7 +117,7 @@ const Inner: React.FC<
return
}

if (!dismissOnESC || compositioning) {
if (!dismissOnESC || suspendDismissOnESC) {
return
}

Expand Down Expand Up @@ -131,14 +148,6 @@ const Inner: React.FC<
handleKeyboardEvent(event)
})

useNativeEventListener('compositionstart', () => {
setCompositioning(true)
})

useNativeEventListener('compositionend', () => {
setCompositioning(false)
})

return (
<div
{...(testId ? { 'data-test-id': testId } : {})}
Expand Down
12 changes: 11 additions & 1 deletion src/components/Dialogs/MomentDetailDialog/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { Editor } from '@matters/matters-editor'
import classNames from 'classnames'
import { useEffect, useState } from 'react'

import { ADD_MOMENT_COMMENT_MENTION } from '~/common/enums'
import {
ADD_MOMENT_COMMENT_MENTION,
DISABLE_SUSPEND_DISMISS_ON_ESC,
ENABLE_SUSPEND_DISMISS_ON_ESC,
} from '~/common/enums'
import { makeMentionElement, toPath } from '~/common/utils'
import {
MomentDigestDetail,
Expand Down Expand Up @@ -48,6 +52,12 @@ const MomentDetailDialogContent = ({
if (editor && editing) {
editor.commands.focus('end')
}

if (editing) {
window.dispatchEvent(new CustomEvent(ENABLE_SUSPEND_DISMISS_ON_ESC))
} else {
window.dispatchEvent(new CustomEvent(DISABLE_SUSPEND_DISMISS_ON_ESC))
}
}, [editor, editing])

useEventListener(
Expand Down
1 change: 1 addition & 0 deletions src/components/Forms/MomentCommentForm/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

& :global(.ProseMirror),
& :global(.tiptap) {
min-height: 4rem;
max-height: 5.5rem;
}
}
Expand Down

0 comments on commit 128abb7

Please sign in to comment.