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

Gutenberg doesn't prevent default html events #49355

Closed
cawa-93 opened this issue Mar 25, 2023 · 5 comments
Closed

Gutenberg doesn't prevent default html events #49355

cawa-93 opened this issue Mar 25, 2023 · 5 comments
Labels
Browser Issues Issues or PRs that are related to browser specific problems [Type] Enhancement A suggestion for improvement.

Comments

@cawa-93
Copy link
Contributor

cawa-93 commented Mar 25, 2023

Description

I tried to build simple block:

<details>
	<summary><RitchText></summary>
</details>

The problem is that it is not possible to type a space character into the RitchText, because pressing the space-key trigger details to toggle, rather than typing a space character.

Step-by-step reproduction instructions

  1. Create block with markup:
el('details', [
    el('summary', {}, [
        el(RichText, {
            tagName: 'span',
            placeholder: 'Try to type Space',

        })
    ]),
    'Content in details'
])
  1. Add block to content
  2. Try to write some text with spaces.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@carolinan
Copy link
Contributor

Hi,
The keyboard events are disabled per block when needed.
Here is an example of how it is added to the pull request for the details block:

onClick={ ( event ) => event.preventDefault() }

@mrfoxtalbot mrfoxtalbot added the [Type] Enhancement A suggestion for improvement. label Mar 27, 2023
@cawa-93
Copy link
Contributor Author

cawa-93 commented Mar 27, 2023

Hi, The keyboard events are disabled per block when needed. Here is an example of how it is added to the pull request for the details block:

onClick={ ( event ) => event.preventDefault() }

Sorry, but I don't really understand what you mean.

I tried add onClick={ ( event ) => event.preventDefault() } to summary in my block. In this case, pressing the spacebar does prevent toggling details, but at the same time the space character is not entered into RichText. I also tried prevent onKeyUp and got same effect - details doesn't toggle when I press spacebar, but space chapter doesn't entered. I tried prevent onKeyDown as well. In this case, no text is entering at all

@carolinan
Copy link
Contributor

carolinan commented Mar 27, 2023

If you look closer at the linked pull request:
The <summary> is a wrapper for the richtext. The preventDefault is on the summary, not the richtext, this allows typing space in the richtext.
In the editor, the <details> is opened when selected:

open={ hasSelection || showContent }

But in general I think it needs to be added per block, that Gutenberg should not prevent these events by default.
There are some more examples. Several links are prevented from being opened inside the editor:
https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/avatar/edit.js#L155

@cawa-93
Copy link
Contributor Author

cawa-93 commented Mar 27, 2023

The <summary> is a wrapper for the richtext. The preventDefault is on the summary, not the richtext, this allows typing space in the richtext.

Yeah. It's exacly what I did. My edit function looks like this:

function edit({attributes, setAttributes}) {
    return el('details', {...useBlockProps()}, [
        el('summary', {
            onClick: (event) => event.preventDefault()
        }, [
            el(RichText, {
                value: attributes.label,
                onChange: (newSummary) =>
                    setAttributes({label: newSummary}),
                withoutInteractiveFormatting: true,

                placeholder: 'Try to type Space',
            })
        ]),
        'INNER CONTENT HERE'
    ])
}

UPD I just realized that the problem is not reproduced in Edge. Indeed, In Edge, you CAN type space. But, I test it in Firefox (112.0b7), and there, pressing spacebar doesn't type space chapter. Bug tracker

@skorasaurus skorasaurus added the Browser Issues Issues or PRs that are related to browser specific problems label Mar 27, 2023
@ellatrix
Copy link
Member

This was fixed in #30244 but removed later in #41977. Also, we now have a core details block and the solution there is to use a div inside the summary element. #45055

Ideally, browsers should disable interactivity when an element is content editable (like they do for a link), so I'd recommend reporting it to them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Browser Issues Issues or PRs that are related to browser specific problems [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

5 participants