Skip to content

feat(button-toggle): general component cleanup and support value input in multiple mode #9191

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

Merged
merged 1 commit into from
Mar 13, 2018

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Jan 2, 2018

  • Reworks the MatButtonToggleGroup component to remove the need for the MatButtonToggleGroupMultiple component and to avoid having to implement features in two places.
  • Reworks the MatButtonToggleGroup to use the SelectionModel for managing its state.
  • Switches all of the async button toggle tests to run in fakeAsync.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (value input/output, name input, change event etc.).

Note: this is along the same lines as #2773, however #2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes #9058.

@crisbeto crisbeto requested a review from tinayuangao as a code owner January 2, 2018 13:42
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jan 2, 2018
}
set selected(selected: MatButtonToggle|MatButtonToggle[]|null) {
Copy link
Member

Choose a reason for hiding this comment

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

We usually have spaces between the unioned types

}
})
export class MatButtonToggleGroupMultiple extends _MatButtonToggleGroupMixinBase
Copy link
Member

Choose a reason for hiding this comment

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

This would be a major change since it totally removes the symbol; people may have been using @ViewChild etc. to grab hold of these. Can we leave the symbol in as an alias for the combined one?

@crisbeto
Copy link
Member Author

crisbeto commented Jan 3, 2018

Addressed the feedback @jelbourn.

private _vertical = false;
private _multiple = false;
private _selectionModel: SelectionModel<MatButtonToggle>;
private _tempValue: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add some comments about how this variable is used?

* @param isUserInput Whether the change was a result of a user interaction.
*/
_syncButtonToggle(toggle: MatButtonToggle, select: boolean, isUserInput = false) {
if (!this.multiple && this.selected && !toggle.checked) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we check !toggle.checked here? add some comments?

/**
* @deprecated Use `MatButtonToggleGroup` instead.
*/
export class MatButtonToggleGroupMultiple {}
Copy link
Member

Choose a reason for hiding this comment

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

Add a unit test that queries for this?

@crisbeto crisbeto force-pushed the button-toggle-model-again branch from 8af2daf to 2a27883 Compare January 10, 2018 18:38
@crisbeto
Copy link
Member Author

Addressed the feedback @tinayuangao @jelbourn.

@jelbourn jelbourn added the target: minor This PR is targeted for the next minor release label Jan 10, 2018
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Jan 10, 2018
Copy link
Contributor

@tinayuangao tinayuangao left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn
Copy link
Member

@crisbeto could you rebase this?

@crisbeto crisbeto force-pushed the button-toggle-model-again branch from 2a27883 to 3cacceb Compare January 22, 2018 20:39
@crisbeto
Copy link
Member Author

Rebased.

@crisbeto crisbeto force-pushed the button-toggle-model-again branch from 3cacceb to 4619d4b Compare January 26, 2018 19:22
@Yeradon
Copy link

Yeradon commented Feb 2, 2018

Any updates on this one? @crisbeto @jelbourn @tinayuangao

@crisbeto crisbeto force-pushed the button-toggle-model-again branch from 4619d4b to e7f04df Compare February 3, 2018 17:15
@crisbeto crisbeto force-pushed the button-toggle-model-again branch from e7f04df to 81d63df Compare February 19, 2018 21:39

/** Whether the toggle group is vertical. */
@Input()
get vertical(): boolean { return this._vertical; }
set vertical(value: boolean) { this._vertical = coerceBooleanProperty(value); }
private _vertical: boolean = false;
set vertical(value) {
Copy link
Contributor

@rafaelss95 rafaelss95 Feb 19, 2018

Choose a reason for hiding this comment

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

I think you have removed the type annotation here and in other places by accident, no?

@crisbeto crisbeto force-pushed the button-toggle-model-again branch 2 times, most recently from 7158d0e to 6ff097d Compare February 25, 2018 20:23
@rafaelss95
Copy link
Contributor

rafaelss95 commented Mar 1, 2018

@crisbeto can you add closes #8791 here, please?

ngAfterContentInit() {
// If there was an attempt to assign a value before init, use it to set the
// initial selection, otherwise check the `checked` state of the toggles.
if (this._tempValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need this._tempValue !== null here to accept falsy values.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@crisbeto crisbeto force-pushed the button-toggle-model-again branch from 6ff097d to c5da822 Compare March 12, 2018 18:37
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
@crisbeto crisbeto force-pushed the button-toggle-model-again branch from c5da822 to 79fcf6c Compare March 12, 2018 18:37
@mmalerba mmalerba merged commit a403bac into angular:master Mar 13, 2018
@rhutchison
Copy link

rhutchison commented Mar 26, 2018

Thank you! This should resolve #1039

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MatButtonToggleGroupMultiple lacks value property and change event
8 participants