Skip to content

Commit c1a6b33

Browse files
authored
refactor(cdk-experimental/listbox): create reusable example classes (#31487)
1 parent 35039f0 commit c1a6b33

File tree

16 files changed

+81
-65
lines changed

16 files changed

+81
-65
lines changed

src/components-examples/cdk-experimental/listbox/cdk-listbox-active-descendant/cdk-listbox-active-descendant-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<ul
44
cdkListbox
55
focusMode="activedescendant"
6-
class="example-listbox"
6+
class="example-listbox example-parent"
77
aria-labelledby="active-descendant-label"
88
>
99
<label class="example-label" id="active-descendant-label">Active Descendant Fruits</label>
1010
@for (fruit of fruits; track fruit) {
1111
<li
12-
class="example-option"
12+
class="example-option example-stateful example-selectable"
1313
[value]="fruit"
1414
cdkOption
1515
#option="cdkOption"

src/components-examples/cdk-experimental/listbox/cdk-listbox-configurable/cdk-listbox-configurable-example.css

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
display: block;
3232
}
3333

34-
.example-listbox[aria-disabled='true'] {
35-
opacity: 0.5;
36-
}
37-
3834
.example-listbox[aria-disabled='true'] .example-option {
3935
pointer-events: none;
4036
}
@@ -53,39 +49,3 @@
5349
align-items: center;
5450
border-radius: var(--mat-sys-corner-extra-small);
5551
}
56-
57-
.example-option.cdk-active,
58-
.example-option[aria-disabled='false']:hover {
59-
outline: 1px solid var(--mat-sys-outline);
60-
background: var(--mat-sys-surface-container);
61-
}
62-
63-
.example-option[aria-disabled='false']:focus-within {
64-
outline: 2px solid var(--mat-sys-primary);
65-
background: var(--mat-sys-surface-container);
66-
}
67-
68-
.example-option[aria-disabled='false'][aria-selected='true'] {
69-
background-color: var(--mat-sys-secondary-container);
70-
}
71-
72-
.example-option.cdk-active[aria-disabled='true'],
73-
.example-option[aria-disabled='true']:focus-within {
74-
outline: 2px solid var(--mat-sys-outline);
75-
}
76-
77-
.example-option[aria-disabled='true'] span {
78-
opacity: 0.3;
79-
}
80-
81-
.example-option[aria-disabled='true']::before {
82-
content: '';
83-
position: absolute;
84-
width: 100%;
85-
height: 100%;
86-
top: 0;
87-
left: 0;
88-
border-radius: var(--mat-sys-corner-extra-small);
89-
background-color: var(--mat-sys-on-surface);
90-
opacity: var(--mat-sys-focus-state-layer-opacity);
91-
}

src/components-examples/cdk-experimental/listbox/cdk-listbox-configurable/cdk-listbox-configurable-example.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<!-- #docregion listbox -->
5252
<ul
5353
cdkListbox
54+
#listbox="cdkListbox"
5455
[value]="selection"
5556
[wrap]="wrap.value"
5657
[multi]="multi.value"
@@ -60,22 +61,22 @@
6061
[orientation]="orientation"
6162
[focusMode]="focusMode"
6263
[selectionMode]="selectionMode"
63-
class="example-listbox"
64+
class="example-listbox example-parent"
6465
>
6566
<label class="example-label" id="fruit-example-label">List of Fruits</label>
6667

6768
@for (fruit of fruits; track fruit) {
6869
@let optionDisabled = disabledOptions.includes(fruit);
6970

7071
<li
71-
class="example-option"
72+
class="example-option example-stateful example-selectable"
7273
[disabled]="optionDisabled"
7374
[value]="fruit"
7475
cdkOption
7576
#option="cdkOption"
7677
>
7778
<mat-pseudo-checkbox
78-
[disabled]="optionDisabled"
79+
[disabled]="optionDisabled || listbox.disabled()"
7980
[state]="option.pattern.selected() ? 'checked' : 'unchecked'"
8081
></mat-pseudo-checkbox>
8182
<span>{{ fruit }}</span>

src/components-examples/cdk-experimental/listbox/cdk-listbox-disabled-focusable/cdk-listbox-disabled-focusable-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<ul
44
cdkListbox
55
[skipDisabled]="false"
6-
class="example-listbox"
6+
class="example-listbox example-parent"
77
aria-labelledby="disabled-focusable-label"
88
>
99
<label class="example-label" id="disabled-focusable-label">Disabled Focusable Fruits</label>
1010
@for (fruit of fruits; track fruit; let i = $index) {
1111
<li
12-
class="example-option"
12+
class="example-option example-stateful example-selectable"
1313
[value]="fruit"
1414
[disabled]="i % 2 === 0"
1515
cdkOption

src/components-examples/cdk-experimental/listbox/cdk-listbox-disabled-skipped/cdk-listbox-disabled-skipped-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<ul
44
cdkListbox
55
[skipDisabled]="true"
6-
class="example-listbox"
6+
class="example-listbox example-parent"
77
aria-labelledby="disabled-skipped-label"
88
>
99
<label class="example-label" id="disabled-skipped-label">Disabled Skipped Fruits</label>
1010
@for (fruit of fruits; track fruit; let i = $index) {
1111
<li
12-
class="example-option"
12+
class="example-option example-stateful example-selectable"
1313
[value]="fruit"
1414
[disabled]="i % 2 === 0"
1515
cdkOption

src/components-examples/cdk-experimental/listbox/cdk-listbox-disabled/cdk-listbox-disabled-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<ul
33
cdkListbox
44
[disabled]="true"
5-
class="example-listbox"
5+
class="example-listbox example-parent"
66
aria-labelledby="disabled-label"
77
>
88
<label class="example-label" id="disabled-label">Disabled Fruits</label>
99
@for (fruit of fruits; track fruit) {
1010
<li
11-
class="example-option"
11+
class="example-option example-stateful example-selectable"
1212
[value]="fruit"
1313
cdkOption
1414
#option="cdkOption"

src/components-examples/cdk-experimental/listbox/cdk-listbox-horizontal/cdk-listbox-horizontal-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<ul
44
cdkListbox
55
orientation="horizontal"
6-
class="example-listbox"
6+
class="example-listbox example-parent"
77
aria-labelledby="horizontal-label"
88
>
99
<label class="example-label" id="horizontal-label">Horizontal Fruits</label>
1010
@for (fruit of fruits; track fruit) {
1111
<li
12-
class="example-option"
12+
class="example-option example-stateful example-selectable"
1313
[value]="fruit"
1414
cdkOption
1515
#option="cdkOption"

src/components-examples/cdk-experimental/listbox/cdk-listbox-multi-select-follow-focus/cdk-listbox-multi-select-follow-focus-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
cdkListbox
55
[multi]="true"
66
selectionMode="follow"
7-
class="example-listbox"
7+
class="example-listbox example-parent"
88
aria-labelledby="multi-follow-label"
99
>
1010
<label class="example-label" id="multi-follow-label">Multi Select (Follow Focus) Fruits</label>
1111
@for (fruit of fruits; track fruit) {
1212
<li
13-
class="example-option"
13+
class="example-option example-stateful example-selectable"
1414
[value]="fruit"
1515
cdkOption
1616
#option="cdkOption"

src/components-examples/cdk-experimental/listbox/cdk-listbox-multi-select/cdk-listbox-multi-select-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
cdkListbox
55
[multi]="true"
66
selectionMode="explicit"
7-
class="example-listbox"
7+
class="example-listbox example-parent"
88
aria-labelledby="multi-select-label"
99
>
1010
<label class="example-label" id="multi-select-label">Multi Select Fruits</label>
1111
@for (fruit of fruits; track fruit) {
1212
<li
13-
class="example-option"
13+
class="example-option example-stateful example-selectable"
1414
[value]="fruit"
1515
cdkOption
1616
#option="cdkOption"

src/components-examples/cdk-experimental/listbox/cdk-listbox-readonly/cdk-listbox-readonly-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<ul
44
cdkListbox
55
[readonly]="true"
6-
class="example-listbox"
6+
class="example-listbox example-parent"
77
aria-labelledby="readonly-label"
88
>
99
<label class="example-label" id="readonly-label">Readonly Fruits</label>
1010
@for (fruit of fruits; track fruit) {
1111
<li
12-
class="example-option"
12+
class="example-option example-stateful example-selectable"
1313
[value]="fruit"
1414
cdkOption
1515
#option="cdkOption"

src/components-examples/cdk-experimental/listbox/cdk-listbox-rtl-horizontal/cdk-listbox-rtl-horizontal-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<ul
44
cdkListbox
55
orientation="horizontal"
6-
class="example-listbox"
6+
class="example-listbox example-parent"
77
aria-labelledby="rtl-horizontal-label"
88
>
99
<label class="example-label" id="rtl-horizontal-label">RTL Horizontal Fruits</label>
1010
@for (fruit of fruits; track fruit) {
1111
<li
12-
class="example-option"
12+
class="example-option example-stateful example-selectable"
1313
[value]="fruit"
1414
cdkOption
1515
#option="cdkOption"

src/components-examples/cdk-experimental/listbox/cdk-listbox-single-select-follow-focus/cdk-listbox-single-select-follow-focus-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
cdkListbox
55
[multi]="false"
66
selectionMode="follow"
7-
class="example-listbox"
7+
class="example-listbox example-parent"
88
aria-labelledby="single-follow-label"
99
>
1010
<label class="example-label" id="single-follow-label">Single Select (Follow Focus) Fruits</label>
1111
@for (fruit of fruits; track fruit) {
1212
<li
13-
class="example-option"
13+
class="example-option example-stateful example-selectable"
1414
[value]="fruit"
1515
cdkOption
1616
#option="cdkOption"

src/components-examples/cdk-experimental/listbox/cdk-listbox-single-select/cdk-listbox-single-select-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
cdkListbox
55
[multi]="false"
66
selectionMode="explicit"
7-
class="example-listbox"
7+
class="example-listbox example-parent"
88
aria-labelledby="single-select-label"
99
>
1010
<label class="example-label" id="single-select-label">Single Select Fruits</label>
1111
@for (fruit of fruits; track fruit) {
1212
<li
13-
class="example-option"
13+
class="example-option example-stateful example-selectable"
1414
[value]="fruit"
1515
cdkOption
1616
#option="cdkOption"

src/dev-app/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ filegroup(
153153
filegroup(
154154
name = "dev_app_static_files",
155155
srcs = [
156+
"common-classes.css",
156157
"favicon.ico",
157158
"index.html",
158159
":theme",

src/dev-app/common-classes.css

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.example-surface {
2+
background: var(--mat-sys-surface);
3+
color: var(--mat-sys-on-surface);
4+
}
5+
6+
[aria-disabled='true'] .example-stateful,
7+
.example-stateful[aria-disabled='true'] {
8+
color: color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent);
9+
}
10+
11+
.example-stateful:focus {
12+
background: color-mix(
13+
in srgb,
14+
var(--mat-sys-on-surface) calc(var(--mat-sys-focus-state-layer-opacity) * 100%),
15+
transparent
16+
);
17+
}
18+
19+
.example-stateful:hover {
20+
background: color-mix(
21+
in srgb,
22+
var(--mat-sys-on-surface) calc(var(--mat-sys-hover-state-layer-opacity) * 100%),
23+
transparent
24+
);
25+
}
26+
27+
.example-stateful:focus[aria-disabled='true'],
28+
.example-stateful:hover[aria-disabled='true'],
29+
[aria-disabled='true'] .example-stateful:focus,
30+
[aria-disabled='true'] .example-stateful:hover {
31+
background: var(--mat-sys-surface);
32+
}
33+
34+
.example-selectable[aria-selected='true'],
35+
.example-selectable[aria-checked='true'] {
36+
background: color-mix(
37+
in srgb,
38+
var(--mat-sys-primary) calc(var(--mat-sys-pressed-state-layer-opacity) * 100%),
39+
transparent
40+
);
41+
}
42+
43+
.example-selectable[aria-selected='true']:focus-within,
44+
.example-selectable[aria-checked='true']:focus-within {
45+
outline: var(--mat-sys-primary) solid 2px;
46+
}
47+
48+
[aria-disabled='true'] .example-selectable[aria-selected='true'],
49+
.example-selectable[aria-disabled='true'][aria-selected='true'],
50+
[aria-disabled='true'] .example-selectable[aria-checked='true'],
51+
.example-selectable[aria-disabled='true'][aria-checked='true'] {
52+
background: color-mix(in srgb, var(--mat-sys-on-surface) 12%, transparent);
53+
}

src/dev-app/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap"
1818
rel="stylesheet"
1919
/>
20+
<link href="common-classes.css" rel="stylesheet" />
2021

2122
<!-- FontAwesome for mat-icon demo. -->
2223
<link

0 commit comments

Comments
 (0)