-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add support for read-only and non-selectable elements #5374
Add support for read-only and non-selectable elements #5374
Conversation
fix delete while selected fix type while selected fix failing test add tests add e2e test linter fixes add changeset
🦋 Changeset detectedLatest commit: b842575 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
95ce385
to
2b1499c
Compare
3f77a7e
to
f8270f5
Compare
f8270f5
to
0fb0763
Compare
0fb0763
to
b842575
Compare
After trying to use |
@hernansartorio What you describe is a feature we really need in Slate, but which wasn't my main focus when implementing this. Would you be interested in working on a PR to extend @dylans Any thoughts on this? |
Got it! Just wanted to leave a note for anyone running into the same. I'd be open to if only I could figure out an approach that makes sense. |
I’ll revisit this in the future as it’s not a critical feature for me yet, but after experimenting a bit I found that, for starters, we'd need to set Then it would be a matter of figuring out what should happen when editing contiguous elements (i.e. should hitting backspace in the next element ignore the non-selectable one instead of merging into it?). And probably other edge cases I haven't thought about. |
There are definitely a lot of edge cases to consider, and different use cases will likely want different behavious in those edge cases. When you revisit this, you could start by handling each edge case in whatever way makes most sense at the time. We can add options to configure the behaviour further when the need arises. |
Some thoughts as this is a problem I often have: Ideally we should document best practices on how to render non-editable content from (1) SlateJS inline/element nodes, and (2) not from SlateJS nodes. It would be good to get advise on how to do that without breaking SlateJS:
Interactions between:
Not sure, but is some of this complexity due to the way SlateJS tries to stay in sync with the DOM selection — could we perhaps rely more on the browser and CSS's |
@beorn Sorry for the late reply. You're right that further research and documentation is required to understand how non-editable content (and, by extension, invisible content) can be handled at the consumer level. The In a native contenteditable, setting a child to I can't recall what happens if a void element fails to render its recording.mp4<div contenteditable>
Before
<span contenteditable="false" style="user-select: none">[contenteditable="false" user-select: none]</span>
After
</div> |
Description
isElementReadOnly
(default false, open to suggestions for alternative names) toeditor
. A read-only element behaves much like a void with regard to selection and deletion, but renders itschildren
the same as any other non-void node.isSelectable
toeditor
(default true). A non-selectable element is skipped over when navigating using arrow keys.ignoreNonSelectable
toEditor.nodes
,Editor.positions
,Editor.after
andEditor.before
(default false)Transforms.move
ignores non-selectable elementsIssue
Fixes #5372
Example
https://user-images.githubusercontent.com/4272090/226684680-6c685c4d-85e1-4e45-aa52-413cf6c4892c.mov
Context
The goal of this PR is to support
contentEditable={false}
on inline nodes without the problems described in #5372. While this is already possible by making the node void, doing so changes the way in which the node is rendered, which is a problem for toggling between editable and non-editable states.Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)