Skip to content

Commit

Permalink
fix(button propagation): stop the submit button propagation and close…
Browse files Browse the repository at this point in the history
… the link popover when applying (close #99)
  • Loading branch information
kurian86 committed Nov 6, 2024
1 parent d1ee3e1 commit ba80307
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/extensions/Image/components/ActionImageButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function ActionImageButton(props: any) {
}
function handleLink(e: any) {
e.preventDefault()
e.stopPropagation()

props.editor.chain().focus().setImageInline({ src: link, inline: imageInline }).run()
actionDialogImage.setOpen(false)
Expand Down
1 change: 1 addition & 0 deletions src/extensions/Link/components/LinkEditBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function LinkEditBlock(props: IPropsLinkEditBlock) {

function handleSubmit(event: any) {
event.preventDefault()
event.stopPropagation()
props?.onSetLink(form.link, form.text, openInNewTab)
}

Expand Down
7 changes: 6 additions & 1 deletion src/extensions/Link/components/LinkEditPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useState } from 'react'

import { ActionButton, IconComponent, Popover, PopoverContent, PopoverTrigger } from '@/components'
import LinkEditBlock from '@/extensions/Link/components/LinkEditBlock'
import type { ButtonViewReturnComponentProps } from '@/types'
Expand All @@ -14,14 +16,17 @@ interface IPropsLinkEditPopover {
}

function LinkEditPopover(props: IPropsLinkEditPopover) {
const [open, setOpen] = useState(false)

function onSetLink(link: string, text?: string, openInNewTab?: boolean) {
if (props.action) {
props.action({ link, text, openInNewTab })
setOpen(false)
}
}

return (
<Popover modal>
<Popover modal open={open} onOpenChange={setOpen}>
<PopoverTrigger disabled={props?.disabled} asChild>
<ActionButton
tooltip={props?.tooltip}
Expand Down
1 change: 1 addition & 0 deletions src/extensions/Video/components/ActiveVideoButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function ActionVideoButton(props: any) {
}
function handleLink(e: any) {
e.preventDefault()
e.stopPropagation()

props.editor
.chain()
Expand Down

0 comments on commit ba80307

Please sign in to comment.