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

adobe / spectrum-web-components / 12802187570

16 Jan 2025 04:36AM CUT coverage: 98.206% (-0.003%) from 98.209%
12802187570

Pull #5019

github

web-flow
Merge 012b0d7d4 into cee6892e5
Pull Request #5019: chore: fix update-spectrum-css script

5151 of 5424 branches covered (94.97%)

Branch coverage included in aggregate %.

33006 of 33430 relevant lines covered (98.73%)

380.51 hits per line

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

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

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

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

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

29✔
21
    public override handlePointerdown(event: PointerEvent): void {
29✔
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);
36✔
30
            cleanupAction = requestAnimationFrame(async () => {
36✔
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
            });
36✔
39
        };
36✔
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

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

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