Skip to content

Commit

Permalink
Add writingsuggestions="" attribute
Browse files Browse the repository at this point in the history
It controls user agent-provided writing assistance on input controls. See https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/WritingSuggestions/explainer.md.

Closes whatwg#9065.
  • Loading branch information
sanketj authored Mar 13, 2024
1 parent b2fb4d0 commit a187fec
Showing 1 changed file with 158 additions and 2 deletions.
160 changes: 158 additions & 2 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -11721,6 +11721,7 @@ interface <dfn interface>HTMLElement</dfn> : <span>Element</span> {
readonly attribute DOMString <span data-x="dom-accessKeyLabel">accessKeyLabel</span>;
[<span>CEReactions</span>] attribute boolean <span data-x="dom-draggable">draggable</span>;
[<span>CEReactions</span>] attribute boolean <span data-x="dom-spellcheck">spellcheck</span>;
[<span>CEReactions</span>] attribute DOMString <span data-x="dom-writingSuggestions">writingSuggestions</span>;
[<span>CEReactions</span>] attribute DOMString <span data-x="dom-autocapitalize">autocapitalize</span>;

[<span>CEReactions</span>] attribute [<span>LegacyNullToEmptyString</span>] DOMString <span data-x="dom-innerText">innerText</span>;
Expand Down Expand Up @@ -12990,6 +12991,7 @@ https://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20HTML%3E%
<li><code data-x="attr-tabindex">tabindex</code></li>
<li><code data-x="attr-title">title</code></li>
<li><code data-x="attr-translate">translate</code></li>
<li><code data-x="attr-writingsuggestions">writingsuggestions</code></li>
</ul>

<div w-nodev>
Expand Down Expand Up @@ -81146,7 +81148,7 @@ body { display:none }

<hr>

<p>User agents must only consider the following pieces of text as checkable for the purposes of
<p>User agents should only consider the following pieces of text as checkable for the purposes of
this feature:</p>

<ul>
Expand Down Expand Up @@ -81256,6 +81258,150 @@ body { display:none }
checkers. A user agent could offer on-demand checking, could perform continuous checking while the
checking is enabled, or could use other interfaces.</p>

<h4>Writing suggestions</h4>

<p>User agents offer writing suggestions as users type into editable regions, either in form
controls (e.g., the <code>textarea</code> element) or in elements in an <span data-x="editing
host"> editing host</span>.</p>

<p>The <dfn element-attr for="html-global"><code
data-x="attr-writingsuggestions">writingsuggestions</code></dfn> content attribute is an
<span>enumerated attribute</span> with the following keywords and states:</p>

<table>
<thead>
<tr>
<th>Keyword
<th>State
<th>Brief description
<tbody>
<tr>
<td><dfn attr-value for="html-global/writingsuggestions"><code
data-x="attr-writingsuggestions-true">true</code></dfn>
<td rowspan="2"><dfn data-x="attr-writingsuggestions-true-state">true</dfn>
<td rowspan="2">Writing suggestions should be offered on this element.
</tr>
<tr>
<td>(The empty string)
<tr>
<td><dfn attr-value for="html-global/writingsuggestions"><code
data-x="attr-writingsuggestions-false">false</code></dfn>
<td><dfn data-x="attr-writingsuggestions-false-state">false</dfn>
<td>Writing suggestions should not be offered on this element.
</tr>
</table>

<p>The attribute's <i data-x="missing value default">missing value default</i> is the <dfn
data-x="attr-writingsuggestions-default-state">default</dfn> state. The default state indicates
that the element is to act according to a default behavior, possibly based on the parent
element's own <code data-x="attr-writingsuggestions">writingsuggestions</code> state, as defined
below.</p>

<p>The attribute's <i data-x="invalid value default">invalid value default</i> is the <span
data-x="attr-writingsuggestions-true-state">true</span> state.</p>

<dl class="domintro">
<dt><code data-x=""><var>element</var>.<span subdfn data-x="dom-writingSuggestions">writingSuggestions</span> [ = <var>value</var> ]</code></dt>

<dd>
<p>Returns "<code data-x="">true</code>" if the user agent is to offer writing suggestions under
the scope of the element; otherwise, returns "<code data-x="">false</code>".</p>

<p>Can be set, to override the default and set the <code data-x="attr-writingsuggestions">
writingsuggestions</code> content attribute.</p>
</dd>
</dl>

<div w-nodev>
<p>The <dfn>computed writing suggestions value</dfn> of a given <var>element</var> is
determined by running the following steps:</p>

<ol>
<li><p>If <var>element</var>'s <code data-x="attr-writingsuggestions">writingsuggestions</code>
content attribute is in the <span data-x="attr-writingsuggestions-false-state">false</span>
state, return "<code data-x="">false</code>".</p></li>

<li><p>If <var>element</var>'s <code
data-x="attr-writingsuggestions">writingsuggestions</code> content attribute is in the <span
data-x="attr-writingsuggestions-default-state">default</span> state, <var>element</var> has a
parent element, and the <span>computed writing suggestions value</span> of
<var>element</var>'s parent element is "<code data-x="">false</code>", then return
"<code data-x="">false</code>".</p></li>

<li><p>Return "<code data-x="">true</code>".</p></li>
</ol>

<p>The <dfn attribute for="HTMLElement"><code
data-x="dom-writingSuggestions">writingSuggestions</code></dfn> getter steps are:</p>

<ol>
<li><p>Return <span>this</span>'s <span>computed writing suggestions value</span>.</p></li>
</ol>

<p class="note">The <code data-x="dom-writingSuggestions">writingSuggestions</code> IDL
attribute is not affected by user preferences that override the <code
data-x="attr-writingsuggestions">writingsuggestions</code> content attribute, and therefore
might not reflect the actual writing suggestions state.</p>

<p>The <code data-x="dom-writingSuggestions">writingSuggestions</code> setter steps are:</p>

<ol>
<li><p>Set <span>this</span>'s <code data-x="attr-writingsuggestions">writingsuggestions</code>
content attribute to the given value.</p></li>
</ol>
</div>

<hr>

<p>User agents should only offer suggestions within an element's scope if the
result of running the following algorithm given <var>element</var> returns true:</p>

<ol>
<!-- user override -->

<li><p>If the user has disabled writing suggestions, then return false.</p></li>

<!-- element type -->
<li>
<p>If none of the following conditions are true:</p>

<ul>
<li><p><var>element</var> is an <code>input</code> element whose <code
data-x="attr-input-type">type</code> attribute is in either the <span
data-x="attr-input-type-text">Text</span>, <span
data-x="attr-input-type-search">Search</span>, <span
data-x="attr-input-type-tel">Telephone</span>, <span data-x="attr-input-type-url">URL</span>,
or <span data-x="attr-input-type-email">Email</span> state and is <i
data-x="concept-fe-mutable">mutable</i>;</p></li>

<li><p><var>element</var> is a <code>textarea</code> element that is <i
data-x="concept-fe-mutable">mutable</i>; or</p></li>

<li><p><var>element</var> is an <span data-x="editing host">editing host</span> or is
<span>editable</span></p></li>
</ul>

<p>then return false.</p>
</li>

<!--
content attribute: false on this element, or inherit if there is an ancestor to inherit from
-->

<li><p>If <var>element</var> has an <span>inclusive ancestor</span> with a <code
data-x="attr-writingsuggestions">writingsuggestions</code> content attribute that's not in the
<span data-x="attr-writingsuggestions-default-state">default</span> and the nearest such
ancestor's <code data-x="attr-writingsuggestions">writingsuggestions</code> content attribute is
in the <span data-x="attr-writingsuggestions-false-state">false</span> state, then return
false.</p></li>

<li><p>Otherwise, return true.</p></li>
</ol>

<p class="note">This specification does not define the user interface for writing suggestions.
A user agent could offer on-demand suggestions, continuous suggestions as the user types, inline
suggestions, autofill-like suggestions in a popup, or could use other interfaces.</p>

<h4>Autocapitalization</h4>

<p>Some methods of entering text, for example virtual keyboards on mobile devices, and also voice
Expand Down Expand Up @@ -139954,7 +140100,9 @@ interface <dfn interface>External</dfn> {
<th> <code data-x="">spellcheck</code>
<td> <span data-x="attr-spellcheck">HTML elements</span>
<td> Whether the element is to have its spelling and grammar checked
<td> "<code data-x="">true</code>"; "<code data-x="">false</code>"
<td> "<code data-x="attr-spellcheck-true">true</code>";
"<code data-x="attr-spellcheck-false">false</code>";
the empty string
<tr>
<th> <code data-x="">src</code>
<td> <code data-x="attr-media-src">audio</code>;
Expand Down Expand Up @@ -140142,6 +140290,13 @@ interface <dfn interface>External</dfn> {
<td> How the value of the form control is to be wrapped for <span>form submission</span>
<td> "<code data-x="attr-textarea-wrap-soft">soft</code>";
"<code data-x="attr-textarea-wrap-hard">hard</code>"
<tr>
<th> <code data-x="">writingsuggestions</code>
<td> <span data-x="attr-writingsuggestions">HTML elements</span>
<td> Whether the element can offer writing suggestions or not.
<td> "<code data-x="attr-writingsuggestions-true">true</code>";
"<code data-x="attr-writingsuggestions-false">false</code>";
the empty string
</table>

<p class="tablenote"><small>An asterisk (*) in a cell indicates that the actual rules are more
Expand Down Expand Up @@ -143187,6 +143342,7 @@ INSERT INTERFACES HERE
Samy Kamkar,
Sander van Lambalgen,
Sanjoy Pal,
Sanket Joshi,
Sarah Gebauer,
Sarven Capadisli,
Satrujit Behera,
Expand Down

0 comments on commit a187fec

Please sign in to comment.