Skip to content

fix(material/chips): chips erasing values when focusing out of input #26373

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vmuresanu
Copy link

Fixes #26358

  1. Fix chips erasing values when focusing out of input bound to reactive forms
  2. Add integration tests for edit mode with Reactive Forms approach
  3. Add scenario with Reactive forms in Chips Demo and enable edit mode

@vmuresanu vmuresanu requested review from crisbeto and removed request for zarend and mmalerba January 5, 2023 19:46
@vmuresanu vmuresanu force-pushed the fix-chips-bug branch 2 times, most recently from 5b6970e to aadeb29 Compare January 5, 2023 21:15
(edited)="edit(person, $event)">
<mat-chip-row
*ngFor="let person of people"
[editable]="true"
Copy link
Member

Choose a reason for hiding this comment

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

Why was this one hardcoded to true? We have a button above that is used to toggle the editing functionality.

/>
</mat-form-field>

<h4>Input is last child of chip grid with Reactive Forms</h4>
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a special case for when it's the last child?

Copy link
Author

Choose a reason for hiding this comment

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

The approach with Reactive Forms is slightly different from the one without as you are working with form control. That's why I thought that it would be better to have both versions in example. If you think that it's not worth it I can take it out.

@@ -88,6 +88,9 @@ export class MatChipRow extends MatChip implements AfterViewInit {

@Input() editable: boolean = false;

/** Function that maps option's control value to its display value. Used in case of editable="true" and having an object as value */
@Input() displayWith: ((value: any) => string) | null = null;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that having a function like this is appropriate here. While it does allow us to map the object value to a string to be shown in the chip input, the user is still going to be editing a string so the application author won't be able to re-assign the same value back to the chip.

I'm not the one who wrote the editing functionality, but looking through the template, I can see that we allow authors to provide a their own edit input: https://github.com/angular/components/blob/main/src/material/chips/chip-row.html#L25 Maybe it'll be more appropriate to handle the value at the matChipEditInput level?

Copy link
Author

Choose a reason for hiding this comment

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

We can have an input getByProperty (or some other name) which accepts a property name as a string. And inside matChipEditInput we can check if getByProperty is present, access the value by it, otherwise - we have a string value and we keep the default behavior. Your thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

@crisbeto can you please provide input here? I want to know if it is a good approach before doing a commit and then refactor it

@josephperrott josephperrott requested a review from a team as a code owner December 18, 2024 17:40
@josephperrott josephperrott requested review from crisbeto and removed request for a team December 18, 2024 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(material/chip): Mdc Chip Grid empties all options when using Reactive Forms and focusing out
3 participants