Skip to content

Commit 96a6272

Browse files
author
Ryan A. Johnson
committed
fix(Positionable): correct support for HTML5 IDs
**HTML5** https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute > The id attribute specifies its element's unique identifier (ID). > There are no other restrictions on what form an ID can take; in particular, IDs can consist of just digits, start with a digit, start with an underscore, consist of just punctuation, etc. **HTML4.01** https://www.w3.org/TR/html401/types.html#type-id > ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
1 parent 0137504 commit 96a6272

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

docs/components/popovers/test.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,13 @@ <h2>
253253
</section>
254254

255255
<section>
256-
<h2>Unconventional HTML5-compatible ID</h2>
256+
<h2>HTML5-compatible ID</h2>
257257
<p>
258-
<hx-disclosure aria-controls="f2d90208e58f24216be64de517570c628" class="hxBtn">
259-
<code>hx-disclosure[aria-controls="f2d90208e58f24216be64de517570c628"]</code>
258+
<hx-disclosure aria-controls="2d90208e58f24216be64de517570c628" class="hxBtn">
259+
<code>hx-disclosure[aria-controls="2d90208e58f24216be64de517570c628"]</code>
260260
</hx-disclosure>
261261
</p>
262-
<hx-popover id="f2d90208e58f24216be64de517570c628">
262+
<hx-popover id="2d90208e58f24216be64de517570c628">
263263
<hx-div>
264264
How do you like my hat?
265265
</hx-div>

docs/components/tooltips/test.html

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ <h2>Appearance (formatted)</h2>
4141
</section>
4242

4343
<section>
44-
<h2>Unconventional HTML5-compatible IDs</h2>
44+
<h2>HTML5-compatible IDs</h2>
4545

4646
<div class="hxRow hxAuto">
4747
<div class="hxCol">
4848
<h3>ID on Target</h3>
4949
<p>
50-
<span id="a000c075715ed46eb61242f85e80aaaa1">Hover Here</span>
51-
<hx-tooltip for="a000c075715ed46eb61242f85e80aaaa1">
50+
<span id="000c075715ed46eb61242f85e80aaaa1">Hover Here</span>
51+
<hx-tooltip for="000c075715ed46eb61242f85e80aaaa1">
5252
Do you like my hat?
5353
</hx-tooltip>
5454
</p>
@@ -58,7 +58,7 @@ <h3>ID on Tooltip</h3>
5858
<p>
5959
<span id="html-tip-2">Hover Here</span>
6060
<hx-tooltip
61-
id="b100d90208e58f24216be64de517bbbb2"
61+
id="100d90208e58f24216be64de517bbbb2"
6262
for="html-tip-2"
6363
>
6464
Do you like my hat?
@@ -68,10 +68,10 @@ <h3>ID on Tooltip</h3>
6868
<div class="hxCol">
6969
<h3>ID on Both Tooltip and Target</h3>
7070
<p>
71-
<span id="c200c075715ed46eb61242f85e80cccc3">Hover Here</span>
71+
<span id="200c075715ed46eb61242f85e80cccc3">Hover Here</span>
7272
<hx-tooltip
73-
for="c200c075715ed46eb61242f85e80cccc3"
74-
id="c200d90208e58f24216be64de517dddd3"
73+
for="200c075715ed46eb61242f85e80cccc3"
74+
id="200d90208e58f24216be64de517dddd3"
7575
>
7676
Do you like my hat?
7777
</hx-tooltip>
@@ -129,7 +129,7 @@ <h3>Anchor</h3>
129129
<hx-tooltip for="anchor-target">
130130
#anchor-target
131131
</hx-tooltip>
132-
<p class="hxSubdued hxSubBody">Shouldn't show.</p>
132+
<p class="hxSubdued hxSubBody">Shouldn't show via keyboard focus.</p>
133133
</div>
134134

135135
<div class="hxCol">
@@ -206,6 +206,9 @@ <h3>File Input (hx-file-input)</h3>
206206
<hx-tooltip for="hx-file-input-target">
207207
#hx-file-input-target
208208
</hx-tooltip>
209+
<p>
210+
<hx-error>Adds double tab stop</hx-error>
211+
</p>
209212
</div>
210213

211214
<div class="hxCol">

src/helix-ui/elements/HXDisclosureElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class HXDisclosureElement extends HXElement {
8080
get target () {
8181
if (this.isConnected && !this._target) {
8282
let targetId = this.getAttribute('aria-controls');
83-
this._target = this.getRootNode().querySelector(`#${targetId}`);
83+
this._target = this.getRootNode().querySelector(`[id="${targetId}"]`);
8484
}
8585
return this._target;
8686
}

src/helix-ui/elements/HXTooltipElement.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import shadowMarkup from './HXTooltipElement.html';
33
import shadowStyles from './HXTooltipElement.less';
44

55
import { Positionable } from '../mixins/Positionable';
6-
import { KEYS, mix, generateId } from '../utils';
6+
import { KEYS, defer, mix, generateId } from '../utils';
77

88
const TOOLTIP_DELAY = 500;
99

@@ -34,6 +34,7 @@ export class HXTooltipElement extends _ProtoClass {
3434
this.DEFAULT_POSITION = 'top-center';
3535
this.POSITION_OFFSET = 20;
3636

37+
this.$onConnect = defer(this.$onConnect);
3738
this._onCtrlBlur = this._onCtrlBlur.bind(this);
3839
this._onCtrlFocus = this._onCtrlFocus.bind(this);
3940
this._onCtrlMouseEnter = this._onCtrlMouseEnter.bind(this);
@@ -94,7 +95,7 @@ export class HXTooltipElement extends _ProtoClass {
9495
*/
9596
get controlElement () {
9697
if (this.isConnected) {
97-
return this.getRootNode().querySelector(`#${this.htmlFor}`);
98+
return this.getRootNode().querySelector(`[id="${this.htmlFor}"]`);
9899
}
99100
}
100101

src/helix-ui/mixins/Positionable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export const Positionable = (superclass) => {
179179
}
180180

181181
if (this.relativeTo) {
182-
return this.getRootNode().querySelector(`#${this.relativeTo}`);
182+
return this.getRootNode().querySelector(`[id="${this.relativeTo}"]`);
183183
} else {
184184
return this.controlElement;
185185
}

0 commit comments

Comments
 (0)