Skip to content

Commit

Permalink
Allow to cancel the popovers by clicking away
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymen Steur committed Jun 3, 2020
1 parent fafa072 commit 82e6366
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/MUIRichTextEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ const MUIRichTextEditor: RefForwardingComponent<TMUIRichTextEditorRef, IMUIRichT
confirmLink(...args)
}

const handleClosePrompt = () => {
setState({ ...state, anchorUrlPopover: undefined })
}

const handleToolbarClick = (style: string, type: string, id: string, inlineMode?: boolean) => {
if (type === "inline") {
return toggleInlineStyle(style)
Expand Down Expand Up @@ -748,10 +752,7 @@ const MUIRichTextEditor: RefForwardingComponent<TMUIRichTextEditorRef, IMUIRichT
removeLink()
return
}
setState({
...state,
anchorUrlPopover: undefined
})
handleClosePrompt()
return
}

Expand Down Expand Up @@ -792,10 +793,7 @@ const MUIRichTextEditor: RefForwardingComponent<TMUIRichTextEditorRef, IMUIRichT
if (urlKey) {
removeMedia()
}
setState({
...state,
anchorUrlPopover: undefined
})
handleClosePrompt()
return
}

Expand Down Expand Up @@ -1062,6 +1060,7 @@ const MUIRichTextEditor: RefForwardingComponent<TMUIRichTextEditorRef, IMUIRichT
data={state.urlData}
anchor={state.anchorUrlPopover}
onConfirm={handleConfirmPrompt}
onCancel={handleClosePrompt}
isMedia={state.urlIsMedia}
/>
: null}
Expand Down
2 changes: 2 additions & 0 deletions src/components/UrlPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface IUrlPopoverStateProps extends WithStyles<typeof styles> {
data?: TUrlData
isMedia?: boolean
onConfirm: (isMedia?: boolean, ...args: any) => void
onCancel: () => void
}

const styles = ({ spacing }: Theme) => createStyles({
Expand Down Expand Up @@ -68,6 +69,7 @@ const UrlPopover: FunctionComponent<IUrlPopoverStateProps> = (props) => {
return (
<Popover
open={props.anchor !== undefined}
onClose={props.onCancel}
anchorEl={props.anchor}
anchorOrigin={{
vertical: "bottom",
Expand Down

0 comments on commit 82e6366

Please sign in to comment.