From 53417d49ed2d224f2cd3d005c97ab4bdaab393a7 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 13 Feb 2018 16:38:24 +0100 Subject: [PATCH] feat: add ripples to button-toggle (#9891) * Adds ripples to the `MatButtonToggle` component * Fixes that the focus overlay for button toggles shows on mouse/touch press. * Properly stops monitoring through the `FocusMonitor` on component destroy. * Removes unnecessary mixin for focus-overlay color. Color can be always set, because the overlay will be toggled through `opacity` (performance improvement) Closes #9442 --- .../button-toggle/button-toggle-demo.html | 16 +++++++--- .../button-toggle/_button-toggle-theme.scss | 13 ++------ src/lib/button-toggle/button-toggle-module.ts | 4 +-- src/lib/button-toggle/button-toggle.html | 7 ++++- src/lib/button-toggle/button-toggle.scss | 17 ++++++++-- src/lib/button-toggle/button-toggle.spec.ts | 31 +++++++++++++++++-- src/lib/button-toggle/button-toggle.ts | 18 +++++++++-- src/lib/checkbox/checkbox.ts | 1 + src/lib/radio/radio.ts | 1 + src/lib/slide-toggle/slide-toggle.ts | 1 + 10 files changed, 84 insertions(+), 25 deletions(-) diff --git a/src/demo-app/button-toggle/button-toggle-demo.html b/src/demo-app/button-toggle/button-toggle-demo.html index fdb4c24fafa..198b57041ac 100644 --- a/src/demo-app/button-toggle/button-toggle-demo.html +++ b/src/demo-app/button-toggle/button-toggle-demo.html @@ -10,10 +10,18 @@
- format_align_left - format_align_center - format_align_right - format_align_justify + + format_align_left + + + format_align_center + + + format_align_right + + + format_align_justify +
diff --git a/src/lib/button-toggle/_button-toggle-theme.scss b/src/lib/button-toggle/_button-toggle-theme.scss index f381958472f..42a32a36e79 100644 --- a/src/lib/button-toggle/_button-toggle-theme.scss +++ b/src/lib/button-toggle/_button-toggle-theme.scss @@ -2,15 +2,6 @@ @import '../core/theming/theming'; @import '../core/typography/typography-utils'; -// Applies a focus style to an mat-button-toggle element for each of the supported palettes. -@mixin _mat-button-toggle-focus-color($theme) { - $background: map-get($theme, background); - - .mat-button-toggle-focus-overlay { - background-color: mat-color($background, focused-button); - } -} - @mixin mat-button-toggle-theme($theme) { $foreground: map-get($theme, foreground); $background: map-get($theme, background); @@ -18,8 +9,8 @@ .mat-button-toggle { color: mat-color($foreground, hint-text); - &.cdk-focused { - @include _mat-button-toggle-focus-color($theme); + .mat-button-toggle-focus-overlay { + background-color: mat-color($background, focused-button); } } diff --git a/src/lib/button-toggle/button-toggle-module.ts b/src/lib/button-toggle/button-toggle-module.ts index fca49ad1f6f..372c973ede7 100644 --- a/src/lib/button-toggle/button-toggle-module.ts +++ b/src/lib/button-toggle/button-toggle-module.ts @@ -8,13 +8,13 @@ import {NgModule} from '@angular/core'; import {MatButtonToggleGroup, MatButtonToggleGroupMultiple, MatButtonToggle} from './button-toggle'; -import {MatCommonModule} from '@angular/material/core'; +import {MatCommonModule, MatRippleModule} from '@angular/material/core'; import {UNIQUE_SELECTION_DISPATCHER_PROVIDER} from '@angular/cdk/collections'; import {A11yModule} from '@angular/cdk/a11y'; @NgModule({ - imports: [MatCommonModule, A11yModule], + imports: [MatCommonModule, MatRippleModule, A11yModule], exports: [ MatButtonToggleGroup, MatButtonToggleGroupMultiple, diff --git a/src/lib/button-toggle/button-toggle.html b/src/lib/button-toggle/button-toggle.html index bede6457352..f487d13e4f9 100644 --- a/src/lib/button-toggle/button-toggle.html +++ b/src/lib/button-toggle/button-toggle.html @@ -1,4 +1,4 @@ -