Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit c8519ec

Browse files
authored
fix(slider): Min and max values + improvements (#2073)
- Allow custom ranged `min` and `max` values - Add `valueChange(value: number)` event emitter - Adds `tabIndex` property - Mark as touched on `blur` event - Improved slider examples closes #2019
1 parent 37a4a20 commit c8519ec

File tree

12 files changed

+320
-260
lines changed

12 files changed

+320
-260
lines changed

demos/src/app/app-routing.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const routes: Routes = [
6464
{path: 'ripple-demo', loadChildren: () => import('./components/ripple-demo/ripple.module').then(m => m.RippleModule)},
6565
{path: 'select-demo', loadChildren: () => import('./components/select/module').then(m => m.SelectModule)},
6666
{path: 'shape-docs', loadChildren: () => import('./components/shape/module').then(m => m.ShapeModule)},
67-
{path: 'slider-demo', loadChildren: () => import('./components/slider-demo/slider.module').then(m => m.SliderModule)},
67+
{path: 'slider-demo', loadChildren: () => import('./components/slider/module').then(m => m.SliderModule)},
6868
{
6969
path: 'snackbar-demo', loadChildren: () =>
7070
import('./components/snackbar-demo/snackbar.module').then(m => m.SnackbarModule)

demos/src/app/components/slider-demo/routing.module.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

demos/src/app/components/slider-demo/slider.module.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

demos/src/app/components/slider-demo/api.html renamed to demos/src/app/components/slider/api.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ <h4 mdcSubtitle2>Properties</h4>
4545
<td>disabled: boolean</td>
4646
<td>Disables the slider.</td>
4747
</tr>
48+
<tr>
49+
<td>tabIndex: number</td>
50+
<td>Set the underlying tab index of the component. (Default is 0)</td>
51+
</tr>
4852
</tbody>
4953
</table>
5054

@@ -82,6 +86,12 @@ <h4 mdcSubtitle2>Events</h4>
8286
when a user is dragging the slider or
8387
changing the value using the arrow keys.</td>
8488
</tr>
89+
<tr>
90+
<td>
91+
valueChange(value: number)
92+
</td>
93+
<td>Emits when the value of the slider changes.</td>
94+
</tr>
8595
</tbody>
8696
</table>
8797
</div>
Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
<div class="demo-content">
2-
<mdc-slider #simple discrete [min]="min" [max]="max" [value]="value"></mdc-slider>
3-
<p>Min: {{ simple.min }}</p>
4-
<p>Max: {{ simple.max }}</p>
5-
<p>Value: {{ simple.value }}</p>
6-
<example-viewer [example]="exampleSimple"></example-viewer>
7-
</div>
8-
91
<div class="demo-content">
102
<h3 class="demo-content__headline">Continuous</h3>
11-
<mdc-slider #continuous [min]="continuousMin.value" [max]="continuousMax.value"
12-
value="50" (input)="onInput($event)" (change)="onChange($event)" name="test"></mdc-slider>
3+
<mdc-slider #continuous [min]="continuousMin.value"
4+
[max]="continuousMax.value" value="50" (input)="onInput($event)"
5+
(change)="onChange($event)" name="test"></mdc-slider>
136

14-
<mdc-text-field #continuousMin label="Min" size="1" min="0" max="200" type="number"
15-
value="0"></mdc-text-field>
16-
<mdc-text-field #continuousMax label="Max" type="number" size="1" min="0" max="200"
17-
value="100"></mdc-text-field>
7+
<mdc-text-field #continuousMin label="Min" size="1" min="0" max="200"
8+
type="number" value="0"></mdc-text-field>
9+
<mdc-text-field #continuousMax label="Max" type="number" size="1" min="0"
10+
max="200" value="100"></mdc-text-field>
1811
<div class="demo-layout__row">
1912
<mdc-form-field>
20-
<mdc-checkbox (change)="continuous.disabled = !continuous.disabled"></mdc-checkbox>
13+
<mdc-checkbox (change)="continuous.disabled = !continuous.disabled">
14+
</mdc-checkbox>
2115
<label>Disabled</label>
2216
</mdc-form-field>
2317
</div>
@@ -29,16 +23,19 @@ <h3 class="demo-content__headline">Continuous</h3>
2923

3024
<div class="demo-content">
3125
<h3 class="demo-content__headline">Discrete</h3>
32-
<mdc-slider #discrete discrete [min]="discreteMin.value" [max]="discreteMax.value"
33-
value="25" (input)="discreteInputEventValue = $event.value" (change)="discreteChangeEventValue = $event.value"></mdc-slider>
26+
<mdc-slider #discrete discrete [min]="discreteMin.value"
27+
[max]="discreteMax.value" [value]="discreteValue"
28+
(input)="discreteInputEventValue = $event.value"
29+
(change)="discreteChangeEventValue = $event.value"></mdc-slider>
3430

35-
<mdc-text-field #discreteMin label="Min" type="number" size="1" min="0" max="200"
36-
value="0"></mdc-text-field>
37-
<mdc-text-field #discreteMax label="Max" type="number" size="1" min="0" max="200"
38-
value="100"></mdc-text-field>
31+
<mdc-text-field #discreteMin label="Min" type="number" size="1" min="0"
32+
max="200" value="0"></mdc-text-field>
33+
<mdc-text-field #discreteMax label="Max" type="number" size="1" min="0"
34+
max="200" value="100"></mdc-text-field>
3935
<div class="demo-layout__row">
4036
<mdc-form-field>
41-
<mdc-checkbox (change)="discrete.disabled = !discrete.disabled"></mdc-checkbox>
37+
<mdc-checkbox (change)="discrete.disabled = !discrete.disabled">
38+
</mdc-checkbox>
4239
<label>Disabled</label>
4340
</mdc-form-field>
4441
</div>
@@ -50,8 +47,9 @@ <h3 class="demo-content__headline">Discrete</h3>
5047

5148
<div class="demo-content">
5249
<h3 class="demo-content__headline">Discrete with Tick Marks</h3>
53-
<mdc-slider #demomarkers discrete markers [min]="dmMin.value" [max]="dmMax.value"
54-
[step]="dmStep.value" value="20" (input)="markersInputEventValue = $event.value"
50+
<mdc-slider #demomarkers discrete markers [min]="dmMin.value"
51+
[max]="dmMax.value" [step]="dmStep.value" value="20"
52+
(input)="markersInputEventValue = $event.value"
5553
(change)="markersChangeEventValue = $event.value"></mdc-slider>
5654
<mdc-text-field #dmMin label="Min" type="number" size="1" min="0" max="200"
5755
value="0"></mdc-text-field>
@@ -61,7 +59,8 @@ <h3 class="demo-content__headline">Discrete with Tick Marks</h3>
6159
value="5"></mdc-text-field>
6260
<div class="demo-layout__row">
6361
<mdc-form-field>
64-
<mdc-checkbox (change)="demomarkers.disabled = !demomarkers.disabled"></mdc-checkbox>
62+
<mdc-checkbox (change)="demomarkers.disabled = !demomarkers.disabled">
63+
</mdc-checkbox>
6564
<label>Disabled</label>
6665
</mdc-form-field>
6766
</div>
@@ -71,15 +70,26 @@ <h3 class="demo-content__headline">Discrete with Tick Marks</h3>
7170
<example-viewer [example]="exampleDiscreteTickMarks"></example-viewer>
7271
</div>
7372

73+
<div class="demo-content">
74+
<h3 class="demo-content__headline">Custom range</h3>
75+
<mdc-slider #ranged discrete min="500" max="1000" value="500"></mdc-slider>
76+
<p>Min: {{ ranged.min }}</p>
77+
<p>Max: {{ ranged.max }}</p>
78+
<p>Value: {{ ranged.value }}</p>
79+
<example-viewer [example]="exampleCustomRange"></example-viewer>
80+
</div>
81+
7482
<div class="demo-content">
7583
<h3 class="demo-content__headline">ngModel</h3>
76-
<mdc-slider #demoModel [min]="0" [max]="100" [(ngModel)]="sliderModel"></mdc-slider>
84+
<mdc-slider #demoModel [min]="0" [max]="100" [(ngModel)]="sliderModel">
85+
</mdc-slider>
7786
<p>Value: {{ demoModel.value }}</p>
7887
<example-viewer [example]="exampleNgModel"></example-viewer>
7988
</div>
8089

8190
<div class="demo-content">
8291
<h3 class="demo-content__headline">Theme</h3>
83-
<mdc-slider discrete markers class="demo-slider--custom" value="20"></mdc-slider>
92+
<mdc-slider discrete markers class="demo-slider-custom" value="20">
93+
</mdc-slider>
8494
<example-viewer [example]="exampleTheme"></example-viewer>
8595
</div>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {NgModule} from '@angular/core';
2+
3+
import {SharedModule} from '../../shared.module';
4+
import {RoutingModule, ROUTE_DECLARATIONS} from './routing.module';
5+
6+
@NgModule({
7+
imports: [
8+
SharedModule,
9+
RoutingModule
10+
],
11+
declarations: [ROUTE_DECLARATIONS]
12+
})
13+
export class SliderModule {}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {NgModule} from '@angular/core';
2+
import {Routes, RouterModule} from '@angular/router';
3+
4+
import {Api, Examples, Sass, Slider} from './slider';
5+
6+
export const ROUTE_DECLARATIONS = [
7+
Api,
8+
Examples,
9+
Sass,
10+
Slider
11+
];
12+
13+
const ROUTES: Routes = [
14+
{
15+
path: '', component: Slider,
16+
children: [
17+
{path: '', redirectTo: 'api'},
18+
{path: 'api', component: Api},
19+
{path: 'sass', component: Sass},
20+
{path: 'examples', component: Examples}
21+
]
22+
}
23+
];
24+
25+
@NgModule({
26+
imports: [RouterModule.forChild(ROUTES)],
27+
exports: [RouterModule]
28+
})
29+
export class RoutingModule {}

demos/src/app/components/slider-demo/slider-demo.ts renamed to demos/src/app/components/slider/slider.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {ComponentViewer} from '../../shared/component-viewer';
55
import {MdcSliderChange} from '@angular-mdc/web';
66

77
@Component({template: '<component-viewer></component-viewer>'})
8-
export class SliderDemo implements OnInit {
8+
export class Slider implements OnInit {
99
@ViewChild(ComponentViewer, {static: true}) _componentViewer: ComponentViewer;
1010

1111
ngOnInit(): void {
@@ -38,6 +38,8 @@ export class Examples {
3838
min: number = 10;
3939
value: number = 25;
4040

41+
discreteValue = 50;
42+
4143
sliderModel: number = 10;
4244

4345
continuousInputEventValue: number;
@@ -61,7 +63,7 @@ export class Examples {
6163
// Examples
6264
//
6365

64-
exampleEvents = `import { MdcSliderChange } from '@angular-mdc/web';
66+
exampleEvents = `import {MdcSliderChange} from '@angular-mdc/web';
6567
6668
onInput(event: MdcSliderChange): void {
6769
console.log(event.value);
@@ -71,13 +73,6 @@ onChange(event: MdcSliderChange): void {
7173
console.log(event.value);
7274
}`;
7375

74-
exampleSimple = {
75-
html: `<mdc-slider discrete [min]="min" [max]="max" [value]="value"></mdc-slider>`,
76-
ts: `max: number = 50;
77-
min: number = 10;
78-
value: number = 25;`
79-
};
80-
8176
exampleContinuous = {
8277
html: `<mdc-slider [min]="0" [max]="100" value="50"
8378
(input)="onInput($event)" (change)="onChange($event)"></mdc-slider>`,
@@ -96,13 +91,17 @@ value: number = 25;`
9691
ts: this.exampleEvents
9792
};
9893

94+
exampleCustomRange = {
95+
html: `<mdc-slider #ranged discrete min="500" max="1000" value="500"></mdc-slider>`
96+
};
97+
9998
exampleNgModel = {
10099
html: `<mdc-slider [min]="0" [max]="100" [(ngModel)]="sliderModel"></mdc-slider>`,
101100
ts: `sliderModel: number = 10;`
102101
};
103102

104103
exampleTheme = {
105-
html: `<mdc-slider discrete markers class="demo-slider--custom" value="20"></mdc-slider>`,
104+
html: `<mdc-slider discrete markers class="demo-slider-custom" value="20"></mdc-slider>`,
106105
sass: `https://raw.githubusercontent.com/trimox/angular-mdc-web/master/demos/src/styles/_slider.scss`
107106
};
108107
}

demos/src/styles/_slider.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
@use '@material/slider/_index' as slider;
22
@use '@material/theme/color-palette' as material-color;
33

4-
.demo-slider--custom {
4+
.demo-slider-custom {
55
@include slider.highlight-color(material-color.$red-700);
66
@include slider.rail-color(material-color.$yellow-600, 1);
7-
@include slider.rail-tick-mark-color(white);
7+
@include slider.rail-tick-mark-color(blue);
88
@include slider.thumb-color(material-color.$orange-500);
99
@include slider.focus-halo-color(material-color.$yellow-900);
1010
@include slider.value-pin-fill-color-accessible(material-color.$pink-500);

0 commit comments

Comments
 (0)