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

Feat: [Regions] contenteditable content #3453

Merged
merged 5 commits into from
Jan 4, 2024
Merged

Conversation

kakashy
Copy link
Contributor

@kakashy kakashy commented Dec 29, 2023

Short description

Resolves #3404

Implementation details

Added a contenteditable property to the content generated by the Regions plugin. This property is false by default.

How to test it

Create a new region and tap/click on the text content of the region.

Screenshots

image

Checklist

  • This PR is covered by e2e tests
  • It introduces no breaking API changes

@@ -1,3 +1,4 @@
0
Copy link
Owner

Choose a reason for hiding this comment

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

Nani?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh no! That's embarrasing :D

Comment on lines 243 to 248
if (this.contentEditable && this.content) {
this.content.addEventListener('click', (e) => this.onContentClick(e))
}
if (this.contentEditable && this.content) {
this.content.addEventListener('blur', (e) => this.onContentBlur(e))
}
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
if (this.contentEditable && this.content) {
this.content.addEventListener('click', (e) => this.onContentClick(e))
}
if (this.contentEditable && this.content) {
this.content.addEventListener('blur', (e) => this.onContentBlur(e))
}
if (this.contentEditable && this.content) {
this.content.addEventListener('click', (e) => this.onContentClick(e))
this.content.addEventListener('blur', (e) => this.onContentBlur(e))
}

@katspaugh
Copy link
Owner

Looks good to me overall, left a couple of comments.

As an alternative to the onblur event you could also use onchange, I think. Feels a little more appropriate.

private onContentClick(event: MouseEvent) {
event.stopPropagation()
const contentContainer = event.target as HTMLDivElement
contentContainer.focus()
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this necessary btw? Isn't focusing the default action on click on editable elements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, but with the region container having an event listener for clicks, this (focus on text content) does not happen. The event is immediately propagated to its parent. This function is in hopes that we can step in and handle the content property before propagating the event further. In the latest commit, I have made changes to emit the region-clicked event:

private onContentClick(event: MouseEvent) {
    event.stopPropagation()
    const contentContainer = event.target as HTMLDivElement
    contentContainer.focus()
    this.emit('click', event)
  }

@kakashy
Copy link
Contributor Author

kakashy commented Jan 1, 2024

Thanks for the reviews. I have updated my PR with changes from the main repo along with the suggestions in your notes.

One thing that I am still thinking of is the fact that clicking on a text content and clicking away would trigger a region-updated event even if the text content remains the same. Perhaps a placeholder variable for the text content could help but this might end up cluttering the plugin file.

Copy link
Owner

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

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

Thank you!

@katspaugh katspaugh merged commit 9829f93 into katspaugh:main Jan 4, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants