Skip to content

feat(material-experimental/mdc-chips): switch to evolution API#23931

Merged
crisbeto merged 2 commits into
angular:masterfrom
crisbeto:mdc-chips-deprecated
Jan 11, 2022
Merged

feat(material-experimental/mdc-chips): switch to evolution API#23931
crisbeto merged 2 commits into
angular:masterfrom
crisbeto:mdc-chips-deprecated

Conversation

@crisbeto
Copy link
Copy Markdown
Member

@crisbeto crisbeto commented Nov 9, 2021

Reworks the MDC-based chips to use the new evolution API instead of the deprecated one we're currently using. The new API comes with a lot of markup changes and some behavior differences.

The new API also allows to remove the GridKeyManager, because the keyboard navigation is handled correctly by MDC.

@google-cla google-cla Bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 9, 2021
@crisbeto crisbeto marked this pull request as ready for review November 9, 2021 13:50
@crisbeto crisbeto requested a review from mmalerba as a code owner November 9, 2021 13:50
@crisbeto crisbeto requested review from a team and jelbourn November 9, 2021 13:50
@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release labels Nov 9, 2021
@josephperrott josephperrott removed the request for review from a team November 9, 2021 17:47
@crisbeto crisbeto force-pushed the mdc-chips-deprecated branch 5 times, most recently from 7ca6bb2 to 518c5b3 Compare November 12, 2021 10:27
Copy link
Copy Markdown
Contributor

@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.

Got about halfway through so far

@mixin _base-chip($is-dark) {
$on-surface-state-content: if($is-dark, mdc-color-palette.$grey-50, mdc-color-palette.$grey-900);
$surface:
color.mix(mdc-theme-color.prop-value(on-surface), mdc-theme-color.prop-value(surface), 12%);
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.

Should we add a comment here to explain why we're doing the color mix?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think there's a good explanation tbh, we had the mixing there with the previous implementation so I moved it over to the new one.

Comment thread src/material-experimental/mdc-chips/_chips-theme.scss Outdated
Comment thread src/material-experimental/mdc-chips/chip-action.ts Outdated
// which overrides our own handling. If we detect such a case, assign it to the same property
// as the Angular binding in order to maintain consistency.
if (name === 'tabindex') {
this._updateTabindex(parseInt(value));
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.

Should we use Number(value) here instead? IIRC Number is more predictable (e.g. doesn't interpret a leading 0 as octal)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We've been using parseInt for cases like this everywhere else so I went along with it. I also think that it's unlikely for somebody to write out tabindex="007".

// and error prone, and we need them in several places.
const classList = _elementRef.nativeElement.classList;
const actionType = this._foundation.actionType();
classList.add('mdc-evolution-chip__action', 'mat-mdc-chip-action');
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.

I don't 100% follow- why not set these classes in the host block?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There were two reasons when I was working on this initially:

  1. We still had to support ViewEngine which meant that I would've had to repeat the class bindings in two other places.
  2. I wouldn't have been able to use the enum values in the host block.

I think that both of these issues are resolved with Ivy though.

Comment on lines +152 to +155
static ngAcceptInputType_disabled: BooleanInput;
static ngAcceptInputType_tabIndex: NumberInput;
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.

We can drop these now, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There were some internal issues with #23606 so I decided to keep them here.

Comment on lines +354 to +356
// MDC sets the tabindex directly on the DOM node when the user is navigating which means
// that we may end up with a `0` value from a previous interaction. We reset it manually
// here to ensure that the state is correct.
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.

Should we file an issue for this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is working as expected, as far as MDC is concerned. I don't think that it makes sense for people to customize the tabindex here to begin with, but we need it for backwards compatibility.

Copy link
Copy Markdown
Member Author

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

I've addressed the feedback so far.

@mixin _base-chip($is-dark) {
$on-surface-state-content: if($is-dark, mdc-color-palette.$grey-50, mdc-color-palette.$grey-900);
$surface:
color.mix(mdc-theme-color.prop-value(on-surface), mdc-theme-color.prop-value(surface), 12%);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think there's a good explanation tbh, we had the mixing there with the previous implementation so I moved it over to the new one.

// which overrides our own handling. If we detect such a case, assign it to the same property
// as the Angular binding in order to maintain consistency.
if (name === 'tabindex') {
this._updateTabindex(parseInt(value));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We've been using parseInt for cases like this everywhere else so I went along with it. I also think that it's unlikely for somebody to write out tabindex="007".

// and error prone, and we need them in several places.
const classList = _elementRef.nativeElement.classList;
const actionType = this._foundation.actionType();
classList.add('mdc-evolution-chip__action', 'mat-mdc-chip-action');
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There were two reasons when I was working on this initially:

  1. We still had to support ViewEngine which meant that I would've had to repeat the class bindings in two other places.
  2. I wouldn't have been able to use the enum values in the host block.

I think that both of these issues are resolved with Ivy though.

Comment on lines +152 to +155
static ngAcceptInputType_disabled: BooleanInput;
static ngAcceptInputType_tabIndex: NumberInput;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There were some internal issues with #23606 so I decided to keep them here.

Comment on lines +354 to +356
// MDC sets the tabindex directly on the DOM node when the user is navigating which means
// that we may end up with a `0` value from a previous interaction. We reset it manually
// here to ensure that the state is correct.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is working as expected, as far as MDC is concerned. I don't think that it makes sense for people to customize the tabindex here to begin with, but we need it for backwards compatibility.

@crisbeto crisbeto force-pushed the mdc-chips-deprecated branch from 518c5b3 to cf23b4c Compare November 17, 2021 08:24
Copy link
Copy Markdown
Contributor

@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 the action: merge The PR is ready for merge by the caretaker label Nov 17, 2021
@crisbeto crisbeto force-pushed the mdc-chips-deprecated branch 9 times, most recently from 252953d to 809462b Compare November 24, 2021 14:30
@crisbeto crisbeto force-pushed the mdc-chips-deprecated branch 3 times, most recently from 82dba32 to 0f5247d Compare November 26, 2021 22:47
@crisbeto crisbeto force-pushed the mdc-chips-deprecated branch 8 times, most recently from 54124ef to 012edf4 Compare December 17, 2021 06:27
@crisbeto crisbeto force-pushed the mdc-chips-deprecated branch 12 times, most recently from 62433de to 9f25785 Compare December 25, 2021 20:04
@crisbeto
Copy link
Copy Markdown
Member Author

Heads-up: I've pushed a second commit that simplifies the theming setup for the chips. The previous approach that was using the theme-styles mixin produced very specific CSS which required a lot of hacks internally and added about 35kb of unnecessary CSS to the dev app theme. The new approach only includes the mixins that we need (still public APIs) which allows us to control the specificity and size much better.

@crisbeto crisbeto force-pushed the mdc-chips-deprecated branch from 1020a33 to 496e5dd Compare December 27, 2021 08:07
@andrewseguin andrewseguin removed the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 28, 2021
Reworks the MDC-based chips to use the new `evolution` API instead of the deprecated one we're currently using. The new API comes with a lot of markup changes and some behavior differences.

The new API also allows to remove the `GridKeyManager`, because the keyboard navigation is handled correctly by MDC.
…dle size

Reworks the theme of the MDC-based chips to produce less specific and more compact CSS.
@angular-automatic-lock-bot
Copy link
Copy Markdown

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.

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 P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants