Skip to content

Commit 09a61f3

Browse files
authored
experiment: add checkbox base styles and visual tests (#9313)
1 parent 7fa2df3 commit 09a61f3

28 files changed

Lines changed: 388 additions & 15 deletions

‎dev/checkbox.html‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
@@ -9,14 +9,38 @@
99

1010
<script type="module">
1111
import '@vaadin/checkbox';
12-
import '@vaadin/tooltip';
12+
import '@vaadin/icon';
13+
import '@vaadin/icons';
1314
</script>
1415
</head>
1516

1617
<body>
17-
<vaadin-checkbox>
18-
<label slot="label">I accept <a href="http://vaadin.com">the terms and conditions</a></label>
19-
<vaadin-tooltip slot="tooltip" text="Please read first"></vaadin-tooltip>
20-
</vaadin-checkbox>
18+
<section>
19+
<h2>Label &amp; Description</h2>
20+
<vaadin-checkbox label="Checked" checked></vaadin-checkbox>
21+
<vaadin-checkbox label="Indeterminate" indeterminate></vaadin-checkbox>
22+
<vaadin-checkbox label="Unchecked"></vaadin-checkbox>
23+
</section>
24+
25+
<section>
26+
<h2>All Features</h2>
27+
<vaadin-checkbox
28+
label="Label"
29+
helper-text="Description"
30+
required
31+
error-message="You have to check me."
32+
invalid
33+
></vaadin-checkbox>
34+
</section>
35+
36+
<section>
37+
<h2>Complex Label</h2>
38+
<vaadin-checkbox>
39+
<label slot="label">
40+
<vaadin-icon icon="vaadin:file"></vaadin-icon>
41+
I accept <a href="http://vaadin.com">the terms and conditions</a>
42+
</label>
43+
</vaadin-checkbox>
44+
</section>
2145
</body>
2246
</html>

‎packages/checkbox/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"type": "module",
2222
"files": [
2323
"src",
24+
"!src/styles/*-base-styles.d.ts",
25+
"!src/styles/*-base-styles.js",
2426
"theme",
2527
"vaadin-*.d.ts",
2628
"vaadin-*.js",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import type { CSSResult } from 'lit';
7+
8+
export const checkboxStyles: CSSResult;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import '@vaadin/component-base/src/style-props.js';
7+
import { css } from 'lit';
8+
import { checkable } from '@vaadin/field-base/src/styles/checkable-base-styles.js';
9+
import { field } from '@vaadin/field-base/src/styles/field-base-styles.js';
10+
11+
const checkbox = css`
12+
@layer base {
13+
[part='checkbox']::after {
14+
inset: 0;
15+
mask-image: var(--_vaadin-icon-checkmark);
16+
}
17+
18+
:host([readonly]) {
19+
--vaadin-checkbox-background: transparent;
20+
--vaadin-checkbox-border-color: var(--_vaadin-border-color-strong);
21+
--vaadin-checkbox-color: var(--_vaadin-color-strong);
22+
}
23+
24+
:host([readonly]) [part='checkbox'] {
25+
border-style: dashed;
26+
}
27+
28+
:host([indeterminate]) [part='checkbox']::after {
29+
inset: calc(var(--_border-width) * -1);
30+
mask-image: var(--_vaadin-icon-minus);
31+
}
32+
}
33+
`;
34+
35+
export const checkboxStyles = [field, checkable('checkbox'), checkbox];
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import { sendKeys } from '@vaadin/test-runner-commands';
2+
import { fixtureSync } from '@vaadin/testing-helpers';
3+
import { visualDiff } from '@web/test-runner-visual-regression';
4+
import '../common.js';
5+
import '../../../src/vaadin-checkbox.js';
6+
7+
describe('checkbox', () => {
8+
let div, element;
9+
10+
beforeEach(() => {
11+
div = document.createElement('div');
12+
div.style.display = 'inline-block';
13+
div.style.padding = '10px';
14+
element = fixtureSync('<vaadin-checkbox label="Checkbox"></vaadin-checkbox>', div);
15+
});
16+
17+
describe('states', () => {
18+
it('basic', async () => {
19+
await visualDiff(div, 'state-basic');
20+
});
21+
22+
it('checked', async () => {
23+
element.checked = true;
24+
await visualDiff(div, 'state-checked');
25+
});
26+
27+
it('indeterminate', async () => {
28+
element.indeterminate = true;
29+
await visualDiff(div, 'state-indeterminate');
30+
});
31+
32+
it('required', async () => {
33+
element.required = true;
34+
await visualDiff(div, 'state-required');
35+
});
36+
37+
it('empty', async () => {
38+
element.label = null;
39+
await visualDiff(div, 'state-empty');
40+
});
41+
42+
describe('disabled', () => {
43+
beforeEach(() => {
44+
element.disabled = true;
45+
});
46+
47+
it('basic', async () => {
48+
await visualDiff(div, 'state-disabled');
49+
});
50+
51+
it('checked', async () => {
52+
element.checked = true;
53+
await visualDiff(div, 'state-disabled-checked');
54+
});
55+
56+
it('indeterminate', async () => {
57+
element.indeterminate = true;
58+
await visualDiff(div, 'state-disabled-indeterminate');
59+
});
60+
61+
it('required', async () => {
62+
element.required = true;
63+
await visualDiff(div, 'state-disabled-required');
64+
});
65+
});
66+
67+
describe('readonly', () => {
68+
beforeEach(() => {
69+
element.readonly = true;
70+
});
71+
72+
it('basic', async () => {
73+
await visualDiff(div, 'state-readonly');
74+
});
75+
76+
it('checked', async () => {
77+
element.checked = true;
78+
await visualDiff(div, 'state-readonly-checked');
79+
});
80+
81+
it('indeterminate', async () => {
82+
element.indeterminate = true;
83+
await visualDiff(div, 'state-readonly-indeterminate');
84+
});
85+
});
86+
87+
describe('focus', () => {
88+
it('keyboard focus', async () => {
89+
await sendKeys({ press: 'Tab' });
90+
await visualDiff(div, 'state-focus');
91+
});
92+
93+
it('checked focus', async () => {
94+
element.checked = true;
95+
await sendKeys({ press: 'Tab' });
96+
await visualDiff(div, 'state-focus-checked');
97+
});
98+
99+
it('indeterminate focus', async () => {
100+
element.indeterminate = true;
101+
await sendKeys({ press: 'Tab' });
102+
await visualDiff(div, 'state-focus-indeterminate');
103+
});
104+
105+
it('readonly focus', async () => {
106+
element.readonly = true;
107+
await sendKeys({ press: 'Tab' });
108+
await visualDiff(div, 'state-focus-readonly');
109+
});
110+
});
111+
});
112+
113+
describe('features', () => {
114+
['ltr', 'rtl'].forEach((dir) => {
115+
describe(dir, () => {
116+
before(() => {
117+
document.documentElement.setAttribute('dir', dir);
118+
});
119+
120+
after(() => {
121+
document.documentElement.removeAttribute('dir');
122+
});
123+
124+
it('error message', async () => {
125+
element.errorMessage = 'This field is required';
126+
element.required = true;
127+
element.validate();
128+
await visualDiff(div, `${dir}-error-message`);
129+
});
130+
131+
it('helper text', async () => {
132+
element.helperText = 'Helper text';
133+
await visualDiff(div, `${dir}-helper-text`);
134+
});
135+
});
136+
});
137+
});
138+
});
2.05 KB
Loading
1.49 KB
Loading
2.03 KB
Loading
1.44 KB
Loading
901 Bytes
Loading

0 commit comments

Comments
 (0)