-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow light dom editor to be slotted (#143)
* allow light dom editor to be slotted. * uncomment some thing * add the ability to slot in a light dom editor * add the ability to slot in a light dom editor * add the ability to slot in a light dom editor * working on tests * working on tests * fix test suite * fix test suite * prettier
- Loading branch information
1 parent
a69c1cc
commit 13dce87
Showing
11 changed files
with
139 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"rhino-editor": patch | ||
--- | ||
|
||
fix: link-dialog buttons now have proper hover / focus state. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"rhino-editor": minor | ||
--- | ||
|
||
BREAKING_CHANGE: Allow the light-dom editor to be slotted. Do note, this change may result in a small breaking change for the users relying on the original light-dom structure being `div > div.trix-content`. Most users should not see a difference. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
html { | ||
box-sizing: border-box; | ||
height: 100%; | ||
font-size: 18px; | ||
font-size: 16px; | ||
/* letter-spacing: 0.025em; */ | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
docs/src/_documentation/how_tos/13-add-additional-attributes-onto-the-editor.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: Add Additional Attributes onto the Editor | ||
permalink: /add-additional-attributes-onto-the-editor/ | ||
--- | ||
|
||
Sometimes you may want to add additional attributes directly onto the `contenteditable` of RhinoEditor. | ||
|
||
The easiest way to do this is by slotting in an editor with the attributes you would like. Here's an example of how we | ||
could add `aria-*` attributes onto the editor in cases where perhaps the form failed validation. | ||
|
||
```erb | ||
<rhino-editor> | ||
<!-- This will get replaced by a new <div>, but will have the attributes copied. --> | ||
<div slot="editor" aria-invalid="<%%= object.errors.any? %>" aria-describedby="description-errors"> | ||
</div> | ||
</rhino-editor> | ||
<div id="description-errors"> | ||
<%% if object.errors.any? %> | ||
<%%= object.errors.to_s %> | ||
<%% end %> | ||
</div> | ||
``` | ||
|
||
This will produce something like the following: | ||
|
||
```html | ||
<rhino-editor> | ||
<!-- This will get replaced by a new <div>, but will have the attributes copied. --> | ||
<div slot="editor" aria-invalid="true" aria-describedby="description-errors"> | ||
</div> | ||
</rhino-editor> | ||
|
||
<div id="description-errors"> | ||
Wow dude. You really messed up. What did you even submit? | ||
</div> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// @ts-check | ||
import "rhino-editor" | ||
import { fixture, assert, aTimeout } from "@open-wc/testing" | ||
import { html } from "lit" | ||
|
||
test("Should only render a textbox once", async () => { | ||
const rhinoEditor = await fixture(html`<rhino-editor> | ||
<div slot="editor" aria-describedby="errors" aria-invalid="true" class="my-class"></div> | ||
</rhino-editor>`) | ||
|
||
await aTimeout(100) | ||
|
||
assert.equal(rhinoEditor.querySelectorAll("[role='textbox']").length, 1) | ||
|
||
const editor = rhinoEditor.querySelector(".trix-content") | ||
|
||
// The attributes we put on the editor should not get overwritten when the rendering process happens. | ||
assert.equal(editor?.getAttribute("aria-describedby"), "errors") | ||
assert.equal(editor?.getAttribute("aria-invalid"), "true") | ||
|
||
// Make sure classes don't get overwritten | ||
assert(editor?.classList.contains("my-class")) | ||
assert(editor?.classList.contains("trix-content")) | ||
console.log(editor.outerHTML) | ||
assert(editor?.classList.contains("tiptap")) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters