• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

adobe / spectrum-web-components / 14129001210

28 Mar 2025 12:32PM CUT coverage: 97.999% (-0.003%) from 98.002%
14129001210

Pull #5281

github

web-flow
Merge 92ee990b9 into fa4be70e9
Pull Request #5281: docs(button): updated button docs for accessibility

5324 of 5621 branches covered (94.72%)

Branch coverage included in aggregate %.

33709 of 34209 relevant lines covered (98.54%)

646.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.83
/packages/picker/src/DesktopController.ts
1
/*
30✔
2
Copyright 2024 Adobe. All rights reserved.
30✔
3
This file is licensed to you under the Apache License, Version 2.0 (the "License");
30✔
4
you may not use this file except in compliance with the License. You may obtain a copy
30✔
5
of the License at http://www.apache.org/licenses/LICENSE-2.0
30✔
6

30✔
7
Unless required by applicable law or agreed to in writing, software distributed under
30✔
8
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
30✔
9
OF ANY KIND, either express or implied. See the License for the specific language
30✔
10
governing permissions and limitations under the License.
30✔
11
*/
30✔
12

30✔
13
import {
30✔
14
    InteractionController,
30✔
15
    InteractionTypes,
30✔
16
} from './InteractionController.js';
30✔
17

30✔
18
export class DesktopController extends InteractionController {
30✔
19
    override type = InteractionTypes.desktop;
466✔
20

30✔
21
    public override handlePointerdown(event: PointerEvent): void {
30✔
22
        if (event.button !== 0 || event.pointerType === 'touch') {
21!
23
            return;
×
24
        }
×
25
        this.pointerdownState = this.open;
21✔
26
        this.preventNextToggle = 'maybe';
21✔
27
        let cleanupAction = 0;
21✔
28
        const cleanup = (): void => {
21✔
29
            cancelAnimationFrame(cleanupAction);
38✔
30
            cleanupAction = requestAnimationFrame(async () => {
38✔
31
                document.removeEventListener('pointerup', cleanup);
21✔
32
                document.removeEventListener('pointercancel', cleanup);
21✔
33
                this.target.removeEventListener('click', cleanup);
21✔
34
                requestAnimationFrame(() => {
21✔
35
                    // Complete cleanup on the second animation frame so that `click` can go first.
21✔
36
                    this.preventNextToggle = 'no';
21✔
37
                });
21✔
38
            });
38✔
39
        };
38✔
40
        // Ensure that however the pointer goes up we do `cleanup()`.
21✔
41
        document.addEventListener('pointerup', cleanup);
21✔
42
        document.addEventListener('pointercancel', cleanup);
21✔
43
        this.target.addEventListener('click', cleanup);
21✔
44
        this.handleActivate();
21✔
45
    }
21✔
46

30✔
47
    public override handleActivate(event?: Event): void {
30✔
48
        if (this.enterKeydownOn && this.enterKeydownOn !== this.target) {
38!
49
            return;
×
50
        }
×
51
        if (this.preventNextToggle === 'yes') {
38!
52
            return;
×
53
        }
×
54
        if (event?.type === 'click' && this.open !== this.pointerdownState) {
38✔
55
            // When activation comes from a `click` event ensure that the `pointerup`
17✔
56
            // event didn't already toggle the Picker state before doing so.
17✔
57
            return;
17✔
58
        }
17✔
59
        this.host.toggle();
21✔
60
    }
38✔
61

30✔
62
    override init(): void {
30✔
63
        // Clean up listeners if they've already been bound
938✔
64
        this.abortController?.abort();
938✔
65
        this.abortController = new AbortController();
938✔
66
        const { signal } = this.abortController;
938✔
67
        this.target.addEventListener(
938✔
68
            'click',
938✔
69
            (event: Event) => this.handleActivate(event),
938✔
70
            {
938✔
71
                signal,
938✔
72
            }
938✔
73
        );
938✔
74
        this.target.addEventListener(
938✔
75
            'pointerdown',
938✔
76
            (event: PointerEvent) => this.handlePointerdown(event),
938✔
77
            { signal }
938✔
78
        );
938✔
79
        this.target.addEventListener(
938✔
80
            'focus',
938✔
81
            (event: FocusEvent) => this.handleButtonFocus(event),
938✔
82
            {
938✔
83
                signal,
938✔
84
            }
938✔
85
        );
938✔
86
    }
938✔
87
}
30✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc