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

[WIP] add required attribute to trix-editor #1144

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
max-width: 700px;
}

div {
margin-bottom: 1rem;

label {
display: block;
}

textarea {
width: 100%;
}
}

#output {
margin: 1rem 0 0;
}
Expand Down Expand Up @@ -72,7 +84,21 @@
</head>
<body>
<main>
<trix-editor autofocus class="trix-content" input="input"></trix-editor>
<form>
<h1>Form with required textarea field</h1>
<div>
<trix-editor autofocus required class="trix-content" input="input"></trix-editor>
</div>

<div>
<label for="comments">Your comments</label>
<textarea id="comments" required></textarea>
</div>

<div>
<input type="submit" />
</div>
</form>
<details id="output">
<summary>Output</summary>
<textarea readonly id="input"></textarea>
Expand Down
9 changes: 9 additions & 0 deletions src/trix/elements/trix_editor_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ const autofocus = function(element) {
}
}

const makeRequired = function(element) {
if (element.hasAttribute("required")) {
// element.inputElement.removeAttribute("readonly")
element.inputElement.required = true
console.log("input", element.inputElement)
}
}

const makeEditable = function(element) {
if (element.hasAttribute("contenteditable")) {
return
Expand Down Expand Up @@ -257,6 +265,7 @@ export default class TrixEditorElement extends HTMLElement {
connectedCallback() {
if (!this.hasAttribute("data-trix-internal")) {
makeEditable(this)
makeRequired(this)
addAccessibilityRole(this)
ensureAriaLabel(this)

Expand Down