Skip to content

Fix HTML attribute synchronisation #60

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

Merged
merged 1 commit into from
Oct 7, 2023
Merged
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
47 changes: 21 additions & 26 deletions code-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,28 @@ var codeInput = {
textareaSyncAttributes: [
"aria-*",
"value",
"name",
// Form validation - https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation#using_built-in_form_validation
"required",
"minlength", "maxlength",
"min", "max",
"type",
"pattern"
"pattern",

// Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
"autocomplete",
"autocorrect",
"autofocus",
"cols",
"dirname",
"disabled",
"form",
"maxlength",
"minlength",
"name",
"placeholder",
"readonly",
"required",
"rows",
"spellcheck",
"wrap"
],

/**
Expand Down Expand Up @@ -777,7 +792,8 @@ var codeInput = {
break;
default:
if (codeInput.textareaSyncAttributes.includes(name)) {
if(newValue == null) {
console.log("sync", name, oldValue, newValue);
if(newValue == null || newValue == undefined) { // TODO: Console.Log to check reaches here with disabled attribute; Fix for disabled attr removal
this.textareaElement.removeAttribute(name);
} else {
this.textareaElement.setAttribute(name, newValue);
Expand Down Expand Up @@ -939,27 +955,6 @@ var codeInput = {
return this.textareaElement.reportValidity();
}


/**
* @override
*/
setAttribute(qualifiedName, value) {
super.setAttribute(qualifiedName, value); // code-input
if(this.textareaElement != null) {
this.textareaElement.setAttribute(qualifiedName, value); // textarea
}
}

/**
* @override
*/
getAttribute(qualifiedName) {
if (this.textareaElement == null) {
return super.getAttribute(qualifiedName);
}
return this.textareaElement.getAttribute(qualifiedName); // textarea
}

/**
* Allows plugins to store data in the scope of a single element.
* Key - name of the plugin
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Fully customisable, editable syntax-highlighted textareas.",
"browser": "code-input.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"This is a front-end library, not a Node library. Please see the README for how to use.\" && exit 1"
},
"repository": {
"type": "git",
Expand Down