improve icon button detection; fixes #1475

This commit is contained in:
Cory LaViska
2025-10-14 14:37:02 -04:00
parent 3c0924fac2
commit 1b1cdfb21a
2 changed files with 21 additions and 10 deletions

View File

@@ -20,6 +20,7 @@ Components with the <wa-badge variant="warning">Experimental</wa-badge> badge sh
- Fixed focus outline styles in `<wa-scroller>`, `<wa-dialog>`, and `<wa-drawer>` [issue:1484]
- Fixed a bug that caused icon button labels to not render in frameworks [issue:1542]
- Fixed a bug in `<wa-details>` that caused the `name` property not to reflect [pr:1538]
- Fixed a bug in `<wa-icon>` that caused icon buttons to render when non-text nodes were slotted in [issue:1475]
## 3.0.0-beta.6

View File

@@ -176,22 +176,32 @@ export default class WaButton extends WebAwesomeFormAssociatedElement {
const nodes = this.labelSlot.assignedNodes({ flatten: true });
let hasIconLabel = false;
let hasIcon = false;
let text = '';
let hasText = false;
let hasOtherElements = false;
// If there's only an icon and no text, it's an icon button
// Check all slotted nodes
[...nodes].forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE && (node as WaIcon).localName === 'wa-icon') {
hasIcon = true;
if (!hasIconLabel) hasIconLabel = (node as WaIcon).label !== undefined;
}
if (node.nodeType === Node.ELEMENT_NODE) {
const element = node as HTMLElement;
// Concatenate text nodes
if (node.nodeType === Node.TEXT_NODE) {
text += node.textContent;
if (element.localName === 'wa-icon') {
hasIcon = true;
if (!hasIconLabel) hasIconLabel = (element as WaIcon).label !== undefined;
} else {
// Any other element type means it's not an icon button
hasOtherElements = true;
}
} else if (node.nodeType === Node.TEXT_NODE) {
// Check if text node has actual content
const text = node.textContent?.trim() || '';
if (text.length > 0) {
hasText = true;
}
}
});
this.isIconButton = text.trim() === '' && hasIcon;
// It's only an icon button if there's an icon and nothing else
this.isIconButton = hasIcon && !hasText && !hasOtherElements;
if (this.isIconButton && !hasIconLabel) {
console.warn(