• 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

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

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

2✔
13
import {
2✔
14
    CSSResultArray,
2✔
15
    html,
2✔
16
    nothing,
2✔
17
    PropertyValues,
2✔
18
    SpectrumElement,
2✔
19
    TemplateResult,
2✔
20
} from '@spectrum-web-components/base';
2✔
21
import { property } from '@spectrum-web-components/base/src/decorators.js';
2✔
22
import { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared/src/focus-visible.js';
2✔
23
import { ObserveSlotPresence } from '@spectrum-web-components/shared/src/observe-slot-presence.js';
2✔
24
import { ObserveSlotText } from '@spectrum-web-components/shared/src/observe-slot-text.js';
2✔
25
import { randomID } from '@spectrum-web-components/shared/src/random-id.js';
2✔
26

2✔
27
import tabItemStyles from './tab.css.js';
2✔
28

2✔
29
/**
2✔
30
 * @element sp-tab
2✔
31
 *
2✔
32
 * @slot - text label of the Tab
2✔
33
 * @slot icon - The icon that appears on the left of the label
2✔
34
 */
2✔
35
export class Tab extends FocusVisiblePolyfillMixin(
2✔
36
    ObserveSlotText(ObserveSlotPresence(SpectrumElement, '[slot="icon"]'), '')
2✔
37
) {
2✔
38
    public static override get styles(): CSSResultArray {
3✔
39
        return [tabItemStyles];
3✔
40
    }
3✔
41

3✔
42
    protected get hasIcon(): boolean {
3✔
43
        return this.slotContentIsPresent;
7✔
44
    }
7✔
45

3✔
46
    protected get hasLabel(): boolean {
3✔
47
        return !!this.label || this.slotHasContent;
7!
48
    }
7✔
49

3✔
50
    @property({ type: Boolean, reflect: true })
3✔
51
    public disabled = false;
3✔
52

3✔
53
    @property({ reflect: true })
3✔
54
    public label = '';
3✔
55

3✔
56
    @property({ type: Boolean, reflect: true })
3✔
57
    public selected = false;
3✔
58

3✔
59
    @property({ type: Boolean, reflect: true })
3✔
60
    public vertical = false;
3✔
61

3✔
62
    @property({ type: String, reflect: true })
3✔
63
    public value = '';
3✔
64

2✔
65
    protected override render(): TemplateResult {
2✔
66
        return html`
7✔
67
            ${this.hasIcon
7!
68
                ? html`
×
69
                      <slot name="icon"></slot>
7✔
70
                  `
7✔
71
                : nothing}
7✔
72
            <label id="item-label" ?hidden=${!this.hasLabel}>
7✔
73
                ${this.slotHasContent ? nothing : this.label}
7✔
74
                <slot>${this.label}</slot>
7✔
75
            </label>
7✔
76
        `;
7✔
77
    }
7✔
78

2✔
79
    protected override firstUpdated(changes: PropertyValues): void {
2✔
80
        super.firstUpdated(changes);
3✔
81
        this.setAttribute('role', 'tab');
3✔
82
        if (!this.hasAttribute('id')) {
3✔
83
            this.id = `sp-tab-${randomID()}`;
3✔
84
        }
3✔
85
    }
3✔
86

2✔
87
    protected override updated(changes: PropertyValues): void {
2✔
88
        super.updated(changes);
7✔
89
        if (changes.has('selected')) {
7✔
90
            this.setAttribute(
3✔
91
                'aria-selected',
3✔
92
                this.selected ? 'true' : 'false'
3!
93
            );
3✔
94
            this.setAttribute('tabindex', this.selected ? '0' : '-1');
3!
95
        }
3✔
96
        if (changes.has('disabled')) {
7✔
97
            if (this.disabled) {
3!
98
                this.setAttribute('aria-disabled', 'true');
×
99
            } else {
3✔
100
                this.removeAttribute('aria-disabled');
3✔
101
            }
3✔
102
        }
3✔
103
    }
7✔
104
}
2✔
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