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

adobe / spectrum-web-components / 15073691922

16 May 2025 05:07PM CUT coverage: 97.992%. First build
15073691922

Pull #5222

github

web-flow
Merge a1497f9a8 into 737ce2c7b
Pull Request #5222: chore: migrate workflows from circleci to github actions [SWC-767]

5264 of 5570 branches covered (94.51%)

Branch coverage included in aggregate %.

33627 of 34118 relevant lines covered (98.56%)

650.91 hits per line

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

90.74
/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;
472✔
20

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

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

30✔
62
    override init(): void {
30✔
63
        // Clean up listeners if they've already been bound
950✔
64
        this.abortController?.abort();
950✔
65
        this.abortController = new AbortController();
950✔
66
        const { signal } = this.abortController;
950✔
67
        this.target.addEventListener(
950✔
68
            'click',
950✔
69
            (event: Event) => this.handleActivate(event),
950✔
70
            {
950✔
71
                signal,
950✔
72
            }
950✔
73
        );
950✔
74
        this.target.addEventListener(
950✔
75
            'pointerdown',
950✔
76
            (event: PointerEvent) => this.handlePointerdown(event),
950✔
77
            { signal }
950✔
78
        );
950✔
79
        this.target.addEventListener(
950✔
80
            'focus',
950✔
81
            (event: FocusEvent) => this.handleButtonFocus(event),
950✔
82
            {
950✔
83
                signal,
950✔
84
            }
950✔
85
        );
950✔
86
    }
950✔
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