Skip to content

fix(button): resolve commandfor only when connected - #2592

Merged
rkaraivanov merged 3 commits into
masterfrom
dpetev/button-detached-commandfor-fix
Nov 12, 2026
Merged

rkaraivanov merged 3 commits into
masterfrom
dpetev/button-detached-commandfor-fix

Conversation

@damyanpetev

Copy link
Copy Markdown
Member

Description

Setting commandfor on a detached igc-button or igc-icon-button threw getElementById is not a function: a detached element is its own root node, and elements have no getElementById. Frameworks that set attributes before inserting an element hit this whenever the button is already defined, for example Blazor rendering <IgbButton Commandfor="..."> on a page visited a second time.

The setter now looks up the target only while connected, and connectedCallback resolves it on attach. This also applies a commandfor changed while detached, which used to keep the previous target once the button was attached again.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Testing

Button spec: commandfor set before the button is inserted, and changed while it is detached. Both fail on master with the error above.

Checklist

  • My code follows the project's coding standards
  • I have tested my changes locally
  • I have added a CHANGELOG.md entry under [Unreleased]
  • I have read the contributing guidelines, including the accessibility, dependency and security rules

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings November 12, 2026 13:26
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change still has an active documentation issue because the component spec does not describe the newly supported reconnect and detached-attribute lifecycle behavior.

1 open issue
What changed in this PR

Fixes commandfor resolution for buttons configured while detached by deferring target lookup until connection and re-resolving targets after detached changes or reconnection.

Changes:

  • Defers detached commandfor lookups until connectedCallback.
  • Re-resolves command targets when commandfor changes while detached.
  • Adds regression tests and an Unreleased changelog entry.
File Description
src/​components/​button/​button.spec.ts Adds regression tests for commandfor configured before insertion and changed while the button is detached.
src/​components/​button/​button-base.ts Guards detached target lookups and resolves the commandfor target when the component connects.
CHANGELOG.md Documents the detached-button commandfor fix under Unreleased.

Review effort: Lite

Comment thread src/components/button/button-base.ts Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rkaraivanov
rkaraivanov merged commit b78bce1 into master Nov 12, 2026
10 checks passed
@rkaraivanov
rkaraivanov deleted the dpetev/button-detached-commandfor-fix branch November 12, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants