Skip to content

fix(material-experimental/mdc-chips): removed chip still focusable #18083

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
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/material-experimental/mdc-chips/chip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ describe('MDC-based MatChip', () => {
expect(testComponent.chipRemove).toHaveBeenCalledWith({chip: chipInstance});
});

it('should make the chip non-focusable when it is removed', () => {
chipInstance.remove();
fixture.detectChanges();

const fakeEvent = createFakeEvent('transitionend');
(fakeEvent as any).propertyName = 'width';
chipNativeElement.dispatchEvent(fakeEvent);

expect(chipNativeElement.style.display).toBe('none');
});

it('should be able to disable ripples through ripple global options at runtime', () => {
expect(chipInstance.rippleDisabled).toBe(false, 'Expected chip ripples to be enabled.');

Expand Down
8 changes: 7 additions & 1 deletion src/material-experimental/mdc-chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,13 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
// future.
},
notifyTrailingIconInteraction: () => this.removeIconInteraction.emit(this.id),
notifyRemoval: () => this.removed.emit({chip: this}),
notifyRemoval: () => {
this.removed.emit({ chip: this });

// When MDC removes a chip it just transitions it to `width: 0px` which means that it's still
// in the DOM and it's still focusable. Make it `display: none` so users can't tab into it.
this._elementRef.nativeElement.style.display = 'none';
},
getComputedStyleValue: propertyName => {
// This function is run when a chip is removed so it might be
// invoked during server-side rendering. Add some extra checks just in case.
Expand Down