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

adobe / spectrum-web-components / 14134706573

28 Mar 2025 05:38PM CUT coverage: 98.002%. Remained the same
14134706573

Pull #5288

github

web-flow
Merge 1b2cce3e8 into 54e4c93de
Pull Request #5288: chore: update dependency @spectrum-css/button to v14.1.3

5327 of 5623 branches covered (94.74%)

Branch coverage included in aggregate %.

33711 of 34211 relevant lines covered (98.54%)

647.99 hits per line

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

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

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

18✔
13
import {
18✔
14
    CSSResultArray,
18✔
15
    html,
18✔
16
    PropertyValues,
18✔
17
    TemplateResult,
18✔
18
} from '@spectrum-web-components/base';
18✔
19
import { state } from '@spectrum-web-components/base/src/decorators.js';
18✔
20
import { ifDefined } from '@spectrum-web-components/base/src/directives.js';
18✔
21
import { property } from '@spectrum-web-components/base/src/decorators.js';
18✔
22
import { DESCRIPTION_ID, PickerBase } from '@spectrum-web-components/picker';
18✔
23
import '@spectrum-web-components/action-button/sp-action-button.js';
18✔
24
import { ObserveSlotPresence } from '@spectrum-web-components/shared/src/observe-slot-presence.js';
18✔
25
import { ObserveSlotText } from '@spectrum-web-components/shared/src/observe-slot-text.js';
18✔
26
import '@spectrum-web-components/icons-workflow/icons/sp-icon-more.js';
18✔
27
import actionMenuStyles from './action-menu.css.js';
18✔
28
import { SlottableRequestEvent } from '@spectrum-web-components/overlay/src/slottable-request-event.js';
18✔
29

18✔
30
/**
18✔
31
 * @element sp-action-menu
18✔
32
 *
18✔
33
 * @slot - menu items to be listed in the Action Menu
18✔
34
 * @slot icon - The icon to use for the Action Menu
18✔
35
 * @slot label - The label to use for the Action Menu
18✔
36
 * @slot label-only - The label to use for the Action Menu (no icon space reserved)
18✔
37
 * @slot tooltip - Tooltip to be applied to the Action Button
18✔
38
 * @attr selects - By default `sp-action-menu` does not manage a selection. If
18✔
39
 *   you'd like for a selection to be held by the `sp-menu` that it presents in
18✔
40
 *   its overlay, use `selects="single" to activate this functionality.
18✔
41
 */
18✔
42
export class ActionMenu extends ObserveSlotPresence(
18✔
43
    ObserveSlotText(PickerBase, 'label'),
18✔
44
    '[slot="label-only"]'
18✔
45
) {
18✔
46
    public static override get styles(): CSSResultArray {
328✔
47
        return [actionMenuStyles];
328✔
48
    }
328✔
49

328✔
50
    @property({ type: String })
328✔
51
    public override selects: undefined | 'single' = undefined;
328✔
52

328✔
53
    @property({ reflect: true, attribute: 'static-color' })
328✔
54
    public staticColor?: 'white' | 'black';
328✔
55

328✔
56
    protected override listRole: 'listbox' | 'menu' = 'menu';
328✔
57
    protected override itemRole = 'menuitem';
328✔
58
    private get hasLabel(): boolean {
328✔
59
        return this.slotHasContent;
1,216✔
60
    }
1,216✔
61

328✔
62
    @state()
328✔
63
    private get labelOnly(): boolean {
328✔
64
        return this.slotContentIsPresent;
1,846✔
65
    }
1,846✔
66

328✔
67
    public override handleSlottableRequest = (
328✔
68
        event: SlottableRequestEvent
85✔
69
    ): void => {
85✔
70
        this.dispatchEvent(new SlottableRequestEvent(event.name, event.data));
85✔
71
    };
85✔
72

18✔
73
    protected override get buttonContent(): TemplateResult[] {
18✔
74
        return [
595✔
75
            html`
595✔
76
                ${this.labelOnly
595!
77
                    ? html``
×
78
                    : html`
595✔
79
                          <slot
595✔
80
                              name="icon"
595✔
81
                              slot="icon"
595✔
82
                              ?icon-only=${!this.hasLabel}
595✔
83
                              ?hidden=${this.labelOnly}
595✔
84
                          >
595✔
85
                              <sp-icon-more
595✔
86
                                  class="icon"
595✔
87
                                  size=${this.size}
595✔
88
                              ></sp-icon-more>
595✔
89
                          </slot>
595✔
90
                      `}
595✔
91
                <slot name="label" ?hidden=${!this.hasLabel}></slot>
595✔
92
                <slot name="label-only"></slot>
595✔
93
            `,
595✔
94
        ];
595✔
95
    }
595✔
96

18✔
97
    protected override render(): TemplateResult {
18✔
98
        if (this.tooltipEl) {
595✔
99
            this.tooltipEl.disabled = this.open;
8✔
100
        }
8✔
101
        return html`
595✔
102
            <sp-action-button
595✔
103
                aria-describedby=${DESCRIPTION_ID}
595✔
104
                ?quiet=${this.quiet}
595✔
105
                ?selected=${this.open}
595✔
106
                static-color=${ifDefined(this.staticColor)}
595✔
107
                aria-haspopup="true"
595✔
108
                aria-controls=${ifDefined(this.open ? 'menu' : undefined)}
595✔
109
                aria-expanded=${this.open ? 'true' : 'false'}
595✔
110
                aria-label=${ifDefined(this.label || undefined)}
595✔
111
                id="button"
595✔
112
                class="button"
595✔
113
                size=${this.size}
595✔
114
                @blur=${this.handleButtonBlur}
595✔
115
                @focus=${this.handleButtonFocus}
595✔
116
                @keydown=${{
595✔
117
                    handleEvent: this.handleEnterKeydown,
595✔
118
                    capture: true,
595✔
119
                }}
595✔
120
                ?disabled=${this.disabled}
595✔
121
            >
595✔
122
                ${this.buttonContent}
595✔
123
            </sp-action-button>
595✔
124
            <slot
595✔
125
                name="tooltip"
595✔
126
                @slotchange=${this.handleTooltipSlotchange}
595✔
127
            ></slot>
595✔
128
            ${this.renderMenu} ${this.renderDescriptionSlot}
595✔
129
        `;
595✔
130
    }
595✔
131

18✔
132
    protected override update(changedProperties: PropertyValues<this>): void {
18✔
133
        if (changedProperties.has('invalid')) {
595✔
134
            this.invalid = false;
330✔
135
        }
330✔
136
        super.update(changedProperties);
595✔
137
    }
595✔
138

18✔
139
    protected override hasAccessibleLabel(): boolean {
18✔
140
        return (
586✔
141
            !!this.label ||
586✔
142
            !!this.getAttribute('aria-label') ||
26✔
143
            !!this.getAttribute('aria-labelledby') ||
26✔
144
            !!this.appliedLabel ||
26✔
145
            this.hasLabel ||
26!
146
            this.labelOnly
×
147
        );
586✔
148
    }
586✔
149

18✔
150
    protected override warnNoLabel(): void {
18✔
151
        window.__swc.warn(
×
152
            this,
×
153
            `<${this.localName}> needs one of the following to be accessible:`,
×
154
            'https://opensource.adobe.com/spectrum-web-components/components/action-menu/#accessibility',
×
155
            {
×
156
                type: 'accessibility',
×
157
                issues: [
×
158
                    `an <sp-field-label> element with a \`for\` attribute referencing the \`id\` of the \`<${this.localName}>\`, or`,
×
159
                    'value supplied to the "label" attribute, which will be displayed visually as placeholder text',
×
160
                    'text content supplied in a <span> with slot="label", or, text content supplied in a <span> with slot="label-only"',
×
161
                    'which will also be displayed visually as placeholder text.',
×
162
                ],
×
163
            }
×
164
        );
×
165
    }
×
166
}
18✔
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