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

adobe / spectrum-web-components / 13114709204

03 Feb 2025 01:34PM CUT coverage: 98.192% (+0.002%) from 98.19%
13114709204

Pull #5060

github

web-flow
Merge e11418a81 into 9dcf7fefc
Pull Request #5060: fix(picker): stop the click events from reaching the elements below picker-tray

5188 of 5464 branches covered (94.95%)

Branch coverage included in aggregate %.

36 of 36 new or added lines in 2 files covered. (100.0%)

33099 of 33528 relevant lines covered (98.72%)

381.19 hits per line

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

93.58
/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;
456✔
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) {
51!
49
            return;
×
50
        }
×
51
        if (this.preventNextToggle === 'yes') {
51✔
52
            return;
6✔
53
        }
6✔
54
        if (event?.type === 'click' && this.open !== this.pointerdownState) {
51✔
55
            // When activation comes from a `click` event ensure that the `pointerup`
11✔
56
            // event didn't already toggle the Picker state before doing so.
11✔
57
            return;
11✔
58
        }
11✔
59
        this.host.toggle();
34✔
60
    }
51✔
61

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