Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(button): fix disable state of the button #12151

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions packages/web-components/src/components/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class C4DButton extends CTAMixin(StableSelectorMixin(CDSButton)) {
@query('a')
_linkNode;

@property()
iconDiv;
@query(`slot[name='icon']`)
iconSlot?: HTMLElement;

@property()
span;
Expand Down Expand Up @@ -135,18 +135,26 @@ class C4DButton extends CTAMixin(StableSelectorMixin(CDSButton)) {

updated(changedProperties) {
super.updated(changedProperties);

if (changedProperties.has('ctaType')) {
if (!this.iconDiv) {
this.iconDiv = this.shadowRoot?.querySelector("slot[name='icon']");
}

const { iconDiv } = this;

iconDiv.querySelector('svg')?.remove();
iconDiv.innerHTML = this._renderButtonIcon();
iconDiv
?.querySelector('svg')
const updateIconForProperties = [
'ctaType',
'disabled',
'tooltipText',
'href',
];
const { iconSlot } = this;

// Note that the parent may render a different <slot name="icon">
// based on changes to either disabled, tooltipText, or href, so we make
// sure to re-render the icon if any of those change, in addition to the
// ctaType.
if (
iconSlot &&
updateIconForProperties.some((prop) => changedProperties.has(prop))
) {
iconSlot.querySelector('svg')?.remove();
iconSlot.innerHTML = this._renderButtonIcon();
iconSlot
.querySelector('svg')
?.classList.add(`${prefix}--card__cta`, `${c4dPrefix}-ce--cta__icon`);
}
}
Expand Down
Loading