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

adobe / spectrum-web-components / 14094674923

26 Mar 2025 10:27PM UTC coverage: 86.218% (-11.8%) from 98.002%
14094674923

Pull #5221

github

web-flow
Merge 2a1ea92e7 into 3184c1e6a
Pull Request #5221: RFC | leverage css module imports in components

1737 of 2032 branches covered (85.48%)

Branch coverage included in aggregate %.

14184 of 16434 relevant lines covered (86.31%)

85.29 hits per line

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

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

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

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

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

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

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

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

8✔
62
    @state()
8✔
63
    private get labelOnly(): boolean {
8✔
64
        return this.slotContentIsPresent;
70✔
65
    }
70✔
66

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

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

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

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

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

4✔
150
    protected override warnNoLabel(): void {
4✔
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
}
4✔
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