@brightspace-ui/core 1.237.3 → 1.238.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,7 +52,7 @@
52
52
  <h2>Tooltip (error)</h2>
53
53
  <d2l-demo-snippet>
54
54
  <template>
55
- <d2l-input-text placeholder="Hover for Error" id="tooltip-error" aria-invalid="true"></d2l-input-text>
55
+ <d2l-input-text placeholder="Hover for Error" id="tooltip-error" aria-invalid="true" label="label"></d2l-input-text>
56
56
  <d2l-tooltip for="tooltip-error" state="error" align="start" offset="10">
57
57
  Your error message will display here
58
58
  </d2l-tooltip>
@@ -1,6 +1,6 @@
1
1
  import { clearDismissible, setDismissible } from '../../helpers/dismissible.js';
2
2
  import { css, html, LitElement } from 'lit-element/lit-element.js';
3
- import { cssEscape, getBoundingAncestor, getOffsetParent } from '../../helpers/dom.js';
3
+ import { cssEscape, elemIdListAdd, getBoundingAncestor, getOffsetParent } from '../../helpers/dom.js';
4
4
  import { announce } from '../../helpers/announce.js';
5
5
  import { bodySmallStyles } from '../typography/styles.js';
6
6
  import { getUniqueId } from '../../helpers/uniqueId.js';
@@ -844,9 +844,9 @@ class Tooltip extends RtlMixin(LitElement) {
844
844
  this.id = this.id || getUniqueId();
845
845
  this.setAttribute('role', 'tooltip');
846
846
  if (this.forType === 'label') {
847
- this._target.setAttribute('aria-labelledby', this.id);
847
+ elemIdListAdd(this._target, 'aria-labelledby', this.id);
848
848
  } else if (!this.announced || isInteractive) {
849
- this._target.setAttribute('aria-describedby', this.id);
849
+ elemIdListAdd(this._target, 'aria-describedby', this.id);
850
850
  }
851
851
  if (logAccessibilityWarning && !isInteractive && !this.announced) {
852
852
  console.warn(
package/helpers/README.md CHANGED
@@ -76,6 +76,12 @@ DOM helper functions to make your life easier.
76
76
  ```js
77
77
  import { ... } from '@brightspace-ui/core/helpers/dom.js';
78
78
 
79
+ // adds a value to an id-list attribute (e.g. aria-labelledby)
80
+ elemIdListAdd(node, attrName, value);
81
+
82
+ // removes a value from an id-list attribute (e.g. aria-labelledby)
83
+ elemIdListRemoves(node, attrName, value);
84
+
79
85
  // returns null or the closest ancestor that fulfills the specified predicate fxn
80
86
  findComposedAncestor(node, predicate);
81
87
 
package/helpers/dom.js CHANGED
@@ -7,6 +7,53 @@ export function cssEscape(val) {
7
7
  return val;
8
8
  }
9
9
 
10
+ export function elemIdListAdd(elem, attrName, value) {
11
+
12
+ if (elem === undefined || elem === null || !elem.getAttribute || !elem.setAttribute) {
13
+ throw new TypeError('elemIdListAdd: "elem" must be a valid DOM Element');
14
+ }
15
+ if (typeof(attrName) !== 'string') {
16
+ throw new TypeError('elemIdListAdd: "attrName" must be a valid string');
17
+ }
18
+ if (typeof(value) !== 'string') {
19
+ throw new TypeError('elemIdListAdd: "value" must be a valid ID string');
20
+ }
21
+
22
+ const parts = elem.hasAttribute(attrName) ? elem.getAttribute(attrName).split(' ') : [];
23
+ if (parts.indexOf(value) > -1) return;
24
+
25
+ parts.push(value);
26
+ elem.setAttribute(attrName, parts.join(' '));
27
+
28
+ }
29
+
30
+ export function elemIdListRemove(elem, attrName, value) {
31
+
32
+ if (elem === undefined || elem === null || !elem.getAttribute || !elem.setAttribute) {
33
+ throw new TypeError('elemIdListRemove: "elem" must be a valid DOM Element');
34
+ }
35
+ if (typeof(attrName) !== 'string') {
36
+ throw new TypeError('elemIdListRemove: "attrName" must be a valid string');
37
+ }
38
+ if (typeof(value) !== 'string') {
39
+ throw new TypeError('elemIdListRemove: "value" must be a valid ID string');
40
+ }
41
+
42
+ const existingValue = elem.getAttribute(attrName) || '';
43
+
44
+ const parts = existingValue.split(' ');
45
+ const index = parts.indexOf(value);
46
+ if (index === -1) return;
47
+
48
+ if (parts.length === 1) {
49
+ elem.removeAttribute(attrName);
50
+ } else {
51
+ parts.splice(index, 1);
52
+ elem.setAttribute(attrName, parts.join(' '));
53
+ }
54
+
55
+ }
56
+
10
57
  export function findComposedAncestor(node, predicate) {
11
58
  while (node) {
12
59
  if (predicate(node) === true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "1.237.3",
3
+ "version": "1.238.0",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",