mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-18 15:09:14 +00:00
Compare commits
2 Commits
native-cod
...
id-fixes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c81817bb5 | ||
|
|
d2342a84e2 |
@@ -36,6 +36,7 @@ Components with the <wa-badge variant="warning">Experimental</wa-badge> badge sh
|
|||||||
- Fixed a bug in `<wa-tooltip>` that prevented tooltips from showing when disconnecting and then reconnecting to the DOM [issue:1595]
|
- Fixed a bug in `<wa-tooltip>` that prevented tooltips from showing when disconnecting and then reconnecting to the DOM [issue:1595]
|
||||||
- Fixed a bug that caused the required `*` in form labels to have incorrect spacing in `<wa-checkbox>` and `<wa-switch>` [issue:1472]
|
- Fixed a bug that caused the required `*` in form labels to have incorrect spacing in `<wa-checkbox>` and `<wa-switch>` [issue:1472]
|
||||||
- Fixed a bug in `<wa-dialog>` and `<wa-drawer>` that caused the component to prematurely hide when certain child elements are used [pr:1636]
|
- Fixed a bug in `<wa-dialog>` and `<wa-drawer>` that caused the component to prematurely hide when certain child elements are used [pr:1636]
|
||||||
|
- Fixed a bug in `<wa-popover>` and `<wa-tooltip>` that prevented dots and other valid ID characters from being used [issue:1648]
|
||||||
- Improved autofill styles in `<wa-input>` so they span the entire width of the visual input [issue:1439]
|
- Improved autofill styles in `<wa-input>` so they span the entire width of the visual input [issue:1439]
|
||||||
- Modified `<wa-slider>` to only show the tooltip on the handle being dragged when in range mode [issue:1320]
|
- Modified `<wa-slider>` to only show the tooltip on the handle being dragged when in range mode [issue:1320]
|
||||||
- Improved [text utilities](/docs/utilities/text/) so that each size modifier always exactly matches the applied font size [pr:1602]
|
- Improved [text utilities](/docs/utilities/text/) so that each size modifier always exactly matches the applied font size [pr:1602]
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ export default class WaPopover extends WebAwesomeElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newAnchor = this.for ? rootNode.querySelector(`#${this.for}`) : null;
|
const newAnchor = this.for ? rootNode.getElementById(this.for) : null;
|
||||||
const oldAnchor = this.anchor;
|
const oldAnchor = this.anchor;
|
||||||
|
|
||||||
if (newAnchor === oldAnchor) {
|
if (newAnchor === oldAnchor) {
|
||||||
|
|||||||
@@ -690,8 +690,8 @@ export default class WaSlider extends WebAwesomeFormAssociatedElement {
|
|||||||
if (!this.withTooltip) return;
|
if (!this.withTooltip) return;
|
||||||
|
|
||||||
// Show only the active tooltip, hide the other
|
// Show only the active tooltip, hide the other
|
||||||
const tooltipMin = this.shadowRoot?.querySelector('#tooltip-thumb-min') as WaTooltip;
|
const tooltipMin = this.shadowRoot?.getElementById('tooltip-thumb-min') as WaTooltip;
|
||||||
const tooltipMax = this.shadowRoot?.querySelector('#tooltip-thumb-max') as WaTooltip;
|
const tooltipMax = this.shadowRoot?.getElementById('tooltip-thumb-max') as WaTooltip;
|
||||||
|
|
||||||
if (this.activeThumb === 'min') {
|
if (this.activeThumb === 'min') {
|
||||||
if (tooltipMin) tooltipMin.open = true;
|
if (tooltipMin) tooltipMin.open = true;
|
||||||
@@ -705,8 +705,8 @@ export default class WaSlider extends WebAwesomeFormAssociatedElement {
|
|||||||
private hideRangeTooltips() {
|
private hideRangeTooltips() {
|
||||||
if (!this.withTooltip) return;
|
if (!this.withTooltip) return;
|
||||||
|
|
||||||
const tooltipMin = this.shadowRoot?.querySelector('#tooltip-thumb-min') as WaTooltip;
|
const tooltipMin = this.shadowRoot?.getElementById('tooltip-thumb-min') as WaTooltip;
|
||||||
const tooltipMax = this.shadowRoot?.querySelector('#tooltip-thumb-max') as WaTooltip;
|
const tooltipMax = this.shadowRoot?.getElementById('tooltip-thumb-max') as WaTooltip;
|
||||||
|
|
||||||
if (tooltipMin) tooltipMin.open = false;
|
if (tooltipMin) tooltipMin.open = false;
|
||||||
if (tooltipMax) tooltipMax.open = false;
|
if (tooltipMax) tooltipMax.open = false;
|
||||||
|
|||||||
@@ -137,8 +137,7 @@ export default class WaTooltip extends WebAwesomeElement {
|
|||||||
this.eventController.abort();
|
this.eventController.abort();
|
||||||
|
|
||||||
if (this.anchor) {
|
if (this.anchor) {
|
||||||
const label = this.anchor.getAttribute('aria-labelledby') || '';
|
this.removeFromAriaLabelledBy(this.anchor, this.id);
|
||||||
this.anchor.setAttribute('aria-labelledby', label.replace(this.id, ''));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,6 +201,34 @@ export default class WaTooltip extends WebAwesomeElement {
|
|||||||
return triggers.includes(triggerType);
|
return triggers.includes(triggerType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Adds the tooltip ID to the aria-labelledby attribute */
|
||||||
|
private addToAriaLabelledBy(element: Element, id: string) {
|
||||||
|
const currentLabel = element.getAttribute('aria-labelledby') || '';
|
||||||
|
const labels = currentLabel.split(/\s+/).filter(Boolean);
|
||||||
|
|
||||||
|
// Only add if not already present
|
||||||
|
if (!labels.includes(id)) {
|
||||||
|
labels.push(id);
|
||||||
|
element.setAttribute('aria-labelledby', labels.join(' '));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes the tooltip ID from the aria-labelledby attribute */
|
||||||
|
private removeFromAriaLabelledBy(element: Element, id: string) {
|
||||||
|
const currentLabel = element.getAttribute('aria-labelledby') || '';
|
||||||
|
const labels = currentLabel.split(/\s+/).filter(Boolean);
|
||||||
|
|
||||||
|
// Remove the ID
|
||||||
|
const filteredLabels = labels.filter(label => label !== id);
|
||||||
|
|
||||||
|
if (filteredLabels.length > 0) {
|
||||||
|
element.setAttribute('aria-labelledby', filteredLabels.join(' '));
|
||||||
|
} else {
|
||||||
|
// Remove the attribute if empty
|
||||||
|
element.removeAttribute('aria-labelledby');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@watch('open', { waitUntilFirstUpdate: true })
|
@watch('open', { waitUntilFirstUpdate: true })
|
||||||
async handleOpenChange() {
|
async handleOpenChange() {
|
||||||
if (this.open) {
|
if (this.open) {
|
||||||
@@ -252,7 +279,7 @@ export default class WaTooltip extends WebAwesomeElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newAnchor = this.for ? rootNode.querySelector(`#${this.for}`) : null;
|
const newAnchor = this.for ? rootNode.getElementById(this.for) : null;
|
||||||
const oldAnchor = this.anchor;
|
const oldAnchor = this.anchor;
|
||||||
|
|
||||||
if (newAnchor === oldAnchor) {
|
if (newAnchor === oldAnchor) {
|
||||||
@@ -261,9 +288,6 @@ export default class WaTooltip extends WebAwesomeElement {
|
|||||||
|
|
||||||
const { signal } = this.eventController;
|
const { signal } = this.eventController;
|
||||||
|
|
||||||
// "\\b" is a space boundary, used for making sure we don't add the tooltip to aria-labelledby twice.
|
|
||||||
const labelRegex = new RegExp(`\\b${this.id}\\b`);
|
|
||||||
|
|
||||||
if (newAnchor) {
|
if (newAnchor) {
|
||||||
/**
|
/**
|
||||||
* We use `aria-labelledby` because it seems to have the most consistent screen reader experience.
|
* We use `aria-labelledby` because it seems to have the most consistent screen reader experience.
|
||||||
@@ -272,10 +296,7 @@ export default class WaTooltip extends WebAwesomeElement {
|
|||||||
* whereas with `aria-labelledby` it'll still read on first focus. The APG does and WAI-ARIA does recommend aria-describedby
|
* whereas with `aria-labelledby` it'll still read on first focus. The APG does and WAI-ARIA does recommend aria-describedby
|
||||||
* so perhaps once we have cross-root aria, we can revisit this decision.
|
* so perhaps once we have cross-root aria, we can revisit this decision.
|
||||||
*/
|
*/
|
||||||
const currentLabel = newAnchor.getAttribute('aria-labelledby') || '';
|
this.addToAriaLabelledBy(newAnchor, this.id);
|
||||||
if (!currentLabel.match(labelRegex)) {
|
|
||||||
newAnchor.setAttribute('aria-labelledby', currentLabel + ' ' + this.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
newAnchor.addEventListener('blur', this.handleBlur, { capture: true, signal });
|
newAnchor.addEventListener('blur', this.handleBlur, { capture: true, signal });
|
||||||
newAnchor.addEventListener('focus', this.handleFocus, { capture: true, signal });
|
newAnchor.addEventListener('focus', this.handleFocus, { capture: true, signal });
|
||||||
@@ -285,8 +306,7 @@ export default class WaTooltip extends WebAwesomeElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (oldAnchor) {
|
if (oldAnchor) {
|
||||||
const label = oldAnchor.getAttribute('aria-labelledby') || '';
|
this.removeFromAriaLabelledBy(oldAnchor, this.id);
|
||||||
oldAnchor.setAttribute('aria-labelledby', label.replace(labelRegex, ''));
|
|
||||||
oldAnchor.removeEventListener('blur', this.handleBlur, { capture: true });
|
oldAnchor.removeEventListener('blur', this.handleBlur, { capture: true });
|
||||||
oldAnchor.removeEventListener('focus', this.handleFocus, { capture: true });
|
oldAnchor.removeEventListener('focus', this.handleFocus, { capture: true });
|
||||||
oldAnchor.removeEventListener('click', this.handleClick);
|
oldAnchor.removeEventListener('click', this.handleClick);
|
||||||
|
|||||||
Reference in New Issue
Block a user