@vaadin/a11y-base
Advanced tools
Comparing version 24.1.0-alpha3 to 24.1.0-alpha4
{ | ||
"name": "@vaadin/a11y-base", | ||
"version": "24.1.0-alpha3", | ||
"version": "24.1.0-alpha4", | ||
"publishConfig": { | ||
@@ -35,3 +35,3 @@ "access": "public" | ||
"@polymer/polymer": "^3.0.0", | ||
"@vaadin/component-base": "24.1.0-alpha3", | ||
"@vaadin/component-base": "24.1.0-alpha4", | ||
"lit": "^2.0.0" | ||
@@ -44,3 +44,3 @@ }, | ||
}, | ||
"gitHead": "077b4a8e8fff063b9eba4581af81f9e152cb852d" | ||
"gitHead": "4494259f3b7532acb604a3048d5b29a4e14b9ca5" | ||
} |
@@ -32,2 +32,9 @@ /** | ||
/** | ||
* Defines the `aria-label` attribute of the target element. | ||
* | ||
* To remove the attribute, pass `null` as `label`. | ||
*/ | ||
setAriaLabel(label: string | null): void; | ||
/** | ||
* Links the target element with a slotted label element | ||
@@ -38,3 +45,3 @@ * via the target's attribute `aria-labelledby`. | ||
*/ | ||
setLabelId(labelId: string | null): void; | ||
setLabelId(labelId: string | null, fromUser: boolean | null): void; | ||
@@ -41,0 +48,0 @@ /** |
@@ -6,3 +6,7 @@ /** | ||
*/ | ||
import { addValueToAttribute, removeValueFromAttribute } from '@vaadin/component-base/src/dom-utils.js'; | ||
import { | ||
removeAriaIDReference, | ||
restoreGeneratedAriaIDReference, | ||
setAriaIDReference, | ||
} from '@vaadin/a11y-base/src/aria-id-reference.js'; | ||
@@ -40,2 +44,3 @@ /** | ||
this.__setHelperIdToAriaAttribute(this.__helperId); | ||
this.setAriaLabel(this.__label); | ||
} | ||
@@ -56,2 +61,14 @@ | ||
/** | ||
* Defines the `aria-label` attribute of the target element. | ||
* | ||
* To remove the attribute, pass `null` as `label`. | ||
* | ||
* @param {string | null | undefined} label | ||
*/ | ||
setAriaLabel(label) { | ||
this.__setAriaLabelToAttribute(label); | ||
this.__label = label; | ||
} | ||
/** | ||
* Links the target element with a slotted label element | ||
@@ -64,5 +81,10 @@ * via the target's attribute `aria-labelledby`. | ||
*/ | ||
setLabelId(labelId) { | ||
this.__setLabelIdToAriaAttribute(labelId, this.__labelId); | ||
this.__labelId = labelId; | ||
setLabelId(labelId, fromUser = false) { | ||
const oldLabelId = fromUser ? this.__labelIdFromUser : this.__labelId; | ||
this.__setLabelIdToAriaAttribute(labelId, oldLabelId, fromUser); | ||
if (fromUser) { | ||
this.__labelIdFromUser = labelId; | ||
} else { | ||
this.__labelId = labelId; | ||
} | ||
} | ||
@@ -99,8 +121,26 @@ | ||
/** | ||
* @param {string | null | undefined} label | ||
* @private | ||
* */ | ||
__setAriaLabelToAttribute(label) { | ||
if (!this.__target) { | ||
return; | ||
} | ||
if (label) { | ||
removeAriaIDReference(this.__target, 'aria-labelledby'); | ||
this.__target.setAttribute('aria-label', label); | ||
} else if (this.__label) { | ||
restoreGeneratedAriaIDReference(this.__target, 'aria-labelledby'); | ||
this.__target.removeAttribute('aria-label'); | ||
} | ||
} | ||
/** | ||
* @param {string | null | undefined} labelId | ||
* @param {string | null | undefined} oldLabelId | ||
* @param {boolean | null | undefined} fromUser | ||
* @private | ||
*/ | ||
__setLabelIdToAriaAttribute(labelId, oldLabelId) { | ||
this.__setAriaAttributeId('aria-labelledby', labelId, oldLabelId); | ||
__setLabelIdToAriaAttribute(labelId, oldLabelId, fromUser) { | ||
setAriaIDReference(this.__target, 'aria-labelledby', { newId: labelId, oldId: oldLabelId, fromUser }); | ||
} | ||
@@ -116,7 +156,4 @@ | ||
// that should guarantee that it's announced when the group is entered. | ||
if (this.__isGroupField) { | ||
this.__setAriaAttributeId('aria-labelledby', errorId, oldErrorId); | ||
} else { | ||
this.__setAriaAttributeId('aria-describedby', errorId, oldErrorId); | ||
} | ||
const ariaAttribute = this.__isGroupField ? 'aria-labelledby' : 'aria-describedby'; | ||
setAriaIDReference(this.__target, ariaAttribute, { newId: errorId, oldId: oldErrorId, fromUser: false }); | ||
} | ||
@@ -132,7 +169,4 @@ | ||
// that should guarantee that it's announced when the group is entered. | ||
if (this.__isGroupField) { | ||
this.__setAriaAttributeId('aria-labelledby', helperId, oldHelperId); | ||
} else { | ||
this.__setAriaAttributeId('aria-describedby', helperId, oldHelperId); | ||
} | ||
const ariaAttribute = this.__isGroupField ? 'aria-labelledby' : 'aria-describedby'; | ||
setAriaIDReference(this.__target, ariaAttribute, { newId: helperId, oldId: oldHelperId, fromUser: false }); | ||
} | ||
@@ -160,21 +194,2 @@ | ||
} | ||
/** | ||
* @param {string | null | undefined} newId | ||
* @param {string | null | undefined} oldId | ||
* @private | ||
*/ | ||
__setAriaAttributeId(attr, newId, oldId) { | ||
if (!this.__target) { | ||
return; | ||
} | ||
if (oldId) { | ||
removeValueFromAttribute(this.__target, attr, oldId); | ||
} | ||
if (newId) { | ||
addValueToAttribute(this.__target, attr, newId); | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98748
35
2599
+ Added@vaadin/component-base@24.1.0-alpha4(transitive)
- Removed@vaadin/component-base@24.1.0-alpha3(transitive)