Skip to content

[Refactor] Combo: render the default "Add item" button inside IgxComboAddItemComponent #18023

Open

Description

@IMinchev64

Follow-up from #18019 (fix for #17992). We agreed to do this separately to keep that PR small, see this thread and this one.

What's not great right now

1. The default button is copy-pasted in both combos

combo.component.html and simple-combo.component.html both have the same block inside <igx-combo-add-item>: the @if (addItemTemplate) / @else branch, the default igxButton="flat" button, its focus class binding and the comment explaining it. On top of that, the add item gets a [customTemplate]="!!addItemTemplate" flag only so it knows which branch the parent rendered.

2. The button's focus class is set from outside

<button igxButton="flat" [class.igx-button--focused]="addItem.active || undefined">

This only works because undefined leaves the class to igxButton's own host binding (_hasKeyboardFocus()). If someone tidies it up to addItem.active, the false wins and the button loses its own keyboard focus ring. A spec in combo.component.spec.ts catches that today, but it's easy to trip over.

Proposal

  • Let IgxComboAddItemComponent render the default button itself. It already knows active, so the focus state stays inside the component. The combos pass it the custom template instead of the customTemplate flag.
  • Drive the button's focused look through an input on the button instead of setting igx-button--focused from outside.
  • The add item component uses an inline <ng-content> template right now. If it renders the button, the template should move to its own .html file (AGENTS.md: no inline templates).

Done when

  • The default button markup lives in one place.
  • Neither combo template binds igx-button--focused directly.
  • The existing add item specs in combo and simple combo still pass: focus ring on keyboard navigation, button keeps its own focus ring while another item is active, custom template keeps the list item focus style, Enter / click adds the item.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions