-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
HTML autocorrect attribute #35692
Merged
+284
−79
Merged
HTML autocorrect attribute #35692
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
60e09dc
HTML autocorrect attribute
hamishwillee 118bab1
Update files/en-us/web/html/element/input/text/index.md
hamishwillee 689f2c0
tidy
hamishwillee 0308881
Add HTMLElement update
hamishwillee 1149859
Improve example
hamishwillee 10a2f13
Fix up autocorrect example following testing
hamishwillee e4aa1a8
Fixup the example for the autocorrect attribute
hamishwillee c4308d9
Commit easy review suggestions.
hamishwillee fb6670d
Update files/en-us/web/api/htmlelement/autocorrect/index.md
hamishwillee bb253bc
DRY example
hamishwillee 0deda46
Update files/en-us/web/api/htmlelement/autocorrect/index.md
hamishwillee 9d34e48
Add note about autocorrect on password, email, url
hamishwillee a094deb
Apply suggestions from code review
hamishwillee 5e87ab0
Update files/en-us/web/html/global_attributes/autocorrect/index.md
hamishwillee 440e0f8
REduce HTMLElement.autocorrect
hamishwillee 218ebb0
Update files/en-us/web/html/global_attributes/autocorrect/index.md
hamishwillee 1d3fa43
remove end tag and prettier
hamishwillee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,102 @@ | ||
--- | ||
title: "HTMLElement: autocorrect property" | ||
short-title: autocorrect | ||
slug: Web/API/HTMLElement/autocorrect | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLElement.autocorrect | ||
--- | ||
|
||
{{APIRef("HTML DOM")}} | ||
|
||
The **`autocorrect`** property of the {{domxref("HTMLElement")}} interface controls whether or not user text input is automatically corrected for spelling and/or punctuation errors. | ||
|
||
The property reflects the value of the [`autocorrect`](/en-US/docs/Web/HTML/Global_attributes/autocorrect) HTML global attribute. | ||
|
||
## Value | ||
|
||
`true` if auto-correction is enabled for the element, and `false` otherwise. | ||
|
||
## Examples | ||
|
||
### Enable and disable autocorrection | ||
|
||
This example shows how you can enable and disable auto-correction. | ||
|
||
#### HTML | ||
|
||
The HTML markup defines a toggle button and an {{htmlelement("input")}} element of [`type="search"`](/en-US/docs/Web/HTML/Element/input/search). | ||
Note that if auto-correction is supported, it will be enabled by default. | ||
|
||
```html | ||
<button id="toggleAutocorrect"></button> | ||
<input type="search" id="searchinput" /> | ||
hamishwillee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
```html hidden | ||
<pre id="log"></pre> | ||
``` | ||
hamishwillee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```css hidden | ||
#log { | ||
height: 100px; | ||
overflow: scroll; | ||
padding: 0.5rem; | ||
border: 1px solid black; | ||
} | ||
``` | ||
|
||
```js hidden | ||
const logElement = document.querySelector("#log"); | ||
function log(text) { | ||
logElement.innerText = `${logElement.innerText}${text}\n`; | ||
logElement.scrollTop = logElement.scrollHeight; | ||
} | ||
``` | ||
|
||
#### JavaScript | ||
|
||
The code first checks whether the `autocorrect` is supported by checking if it is present on the `HTMLElement` prototype. | ||
If it is present, a click handler is added to allow you to toggle the value. | ||
If it is not present, the UI hides the interactive elements and logs that `autocorrect` is not supported. | ||
|
||
```js | ||
const toggleButton = document.querySelector("button"); | ||
const searchInput = document.querySelector("#searchinput"); | ||
|
||
function setButtonText() { | ||
toggleButton.textContent = searchInput.autocorrect ? "Enabled" : "Disabled"; | ||
log(`autocorrect: ${searchInput.autocorrect}`); | ||
} | ||
|
||
if (`autocorrect` in HTMLElement.prototype) { | ||
setButtonText(); | ||
|
||
toggleButton.addEventListener("click", (e) => { | ||
searchInput.autocorrect = !searchInput.autocorrect; | ||
setButtonText(); | ||
}); | ||
} else { | ||
toggleButton.hidden = true; | ||
searchInput.hidden = true; | ||
log("autocorrect not supported"); | ||
} | ||
``` | ||
|
||
#### Result | ||
|
||
Activate the button to toggle the autocorrect value. Enter invalid text into the text box, such as "Carot". | ||
This should be corrected automatically when the feature is enabled. | ||
|
||
{{EmbedLiveSample("Enable and disable autocorrection", "100%", "200")}} | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [`autocapitalize`](/en-US/docs/Web/HTML/Global_attributes/autocapitalize) HTML global attribute |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -23,10 +23,13 @@ _Also inherits properties from its parent, {{DOMxRef("Element")}}._ | |||||
- : Returns a reference to the element's anchor element, or `null` if it doesn't have one. | ||||||
- {{DOMxRef("HTMLElement.attributeStyleMap")}} {{ReadOnlyInline}} | ||||||
- : A {{DOMxRef("StylePropertyMap")}} representing the declarations of the element's [`style`](/en-US/docs/Web/HTML/Global_attributes/style) attribute. | ||||||
- {{domxref("HTMLElement.autocapitalize", "autocapitalize")}} | ||||||
- {{domxref("HTMLElement.autocapitalize")}} | ||||||
- : A string that represents the element's capitalization behavior for user input. Valid values are: `none`, `off`, `on`, `characters`, `words`, `sentences`. | ||||||
- {{domxref("HTMLElement.autofocus")}} | ||||||
- : A boolean value reflecting the [`autofocus`](/en-US/docs/Web/HTML/Element/select#autofocus) HTML global attribute, which indicates whether the control should be focused when the page loads, or when dialog or popover become shown if specified in an element inside {{htmlelement("dialog")}} elements or elements whose popover attribute is set. | ||||||
- {{domxref("HTMLElement.autocorrect")}} | ||||||
- : A boolean that represents whether or not text input by a user should be automatically corrected. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
only implementation is safari, which incorrectly has values of true/false (instead of on/off). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, as per #35692 (comment) |
||||||
This reflects the [`autocorrect`](/en-US/docs/Web/HTML/Global_attributes/autocorrect) HTML global attribute. | ||||||
- {{DOMxRef("HTMLElement.contentEditable")}} | ||||||
- : A string, where a value of `true` means the element is editable and a value of `false` means it isn't. | ||||||
- {{DOMxRef("HTMLElement.dataset")}} {{ReadOnlyInline}} | ||||||
|
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or something like that: the spec says on/off, but safair does true/false, so 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estelle I am pretty sure that what I have here is correct. The spec says the HTML element (shown here) is a boolean that sets/gets
true
/false
. The tag attribute takes a stringon
/off
in spec.See https://html.spec.whatwg.org/multipage/dom.html#htmlelement:
Also the description
The setter sets the attribute to "on"/"off", which I take this to mean that if you output the doc as HTML you'd see the attribute as the string form.
So Safari correctly returns true/false for the HTMLElement.autocorrect, but incorrectly uses the string
'true"
, "false" instead of "on"/"off".