Skip to content

Commit 9c1d71c

Browse files
committed
Minor hover style and spacing updates to <sl-tab-group>
1 parent de86f23 commit 9c1d71c

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed

src/components/tab-group/tab-group.component.ts

+27-2
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,12 @@ export default class SlTabGroup extends ShoelaceElement {
299299
// We can't used offsetLeft/offsetTop here due to a shadow parent issue where neither can getBoundingClientRect
300300
// because it provides invalid values for animating elements: https://bugs.chromium.org/p/chromium/issues/detail?id=920069
301301
const allTabs = this.getAllTabs();
302+
const gap = 16;
302303
const precedingTabs = allTabs.slice(0, allTabs.indexOf(currentTab));
303304
const offset = precedingTabs.reduce(
304305
(previous, current) => ({
305-
left: previous.left + current.clientWidth,
306-
top: previous.top + current.clientHeight
306+
left: previous.left + current.clientWidth + gap,
307+
top: previous.top + current.clientHeight + gap
307308
}),
308309
{ left: 0, top: 0 }
309310
);
@@ -330,6 +331,7 @@ export default class SlTabGroup extends ShoelaceElement {
330331
this.tabs = this.getAllTabs({ includeDisabled: false });
331332
this.panels = this.getAllPanels();
332333
this.syncIndicator();
334+
this.addPlacementClasses();
333335

334336
// After updating, show or hide scroll controls as needed
335337
this.updateComplete.then(() => this.updateScrollControls());
@@ -357,6 +359,29 @@ export default class SlTabGroup extends ShoelaceElement {
357359
}
358360
}
359361

362+
addPlacementClasses() {
363+
if (!this.tabs || this.tabs.length === 0) return;
364+
365+
this.tabs.forEach(tab => {
366+
tab.classList.remove('tab--top', 'tab--bottom', 'tab--start', 'tab--end');
367+
368+
switch (this.placement) {
369+
case 'top':
370+
tab.classList.add('tab--top');
371+
break;
372+
case 'bottom':
373+
tab.classList.add('tab--bottom');
374+
break;
375+
case 'start':
376+
tab.classList.add('tab--start');
377+
break;
378+
case 'end':
379+
tab.classList.add('tab--end');
380+
break;
381+
}
382+
});
383+
}
384+
360385
/** Shows the specified tab panel. */
361386
show(panel: string) {
362387
const tab = this.tabs.find(el => el.panel === panel);

src/components/tab-group/tab-group.styles.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default css`
1717
.tab-group__tabs {
1818
display: flex;
1919
position: relative;
20+
gap: var(--sl-spacing-medium);
2021
}
2122
2223
.tab-group__indicator {

src/components/tab/tab.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ let id = 0;
2828
* @csspart base - The component's base wrapper.
2929
* @csspart close-button - The close button, an `<sl-icon-button>`.
3030
* @csspart close-button__base - The close button's exported `base` part.
31+
*
32+
* @cssproperty --group-track-width - Used to calculate the tab's padding and border width. Must match the tab group's track width (default is 1px).
3133
*/
3234
export default class SlTab extends ShoelaceElement {
3335
static styles: CSSResultGroup = [componentStyles, styles];

src/components/tab/tab.styles.ts

+35-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { css } from 'lit';
22

33
export default css`
44
:host {
5+
--group-track-width: 1px;
6+
57
display: inline-block;
68
}
79
@@ -12,9 +14,8 @@ export default css`
1214
font-size: var(--sl-font-size-small);
1315
font-weight: var(--sl-font-weight-semibold);
1416
line-height: var(--ts-leading-6);
15-
border-radius: var(--sl-border-radius-medium);
1617
color: var(--sl-color-neutral-700);
17-
padding: var(--ts-spacing-large) var(--sl-spacing-medium) var(--sl-spacing-large);
18+
padding: var(--sl-spacing-medium);
1819
white-space: nowrap;
1920
user-select: none;
2021
-webkit-user-select: none;
@@ -24,8 +25,37 @@ export default css`
2425
var(--transition-speed) color;
2526
}
2627
27-
.tab:hover:not(.tab--disabled) {
28-
color: var(--sl-color-primary-600);
28+
.tab:hover:not(.tab--disabled):not(.tab--active) {
29+
color: var(--sl-color-neutral-900);
30+
}
31+
32+
:host(.tab--top) .tab {
33+
border-bottom: calc(var(--sl-spacing-2x-small) - var(--group-track-width)) solid transparent;
34+
padding-bottom: calc(var(--sl-spacing-medium) + var(--group-track-width));
35+
transition: var(--sl-transition-medium) border-color ease;
36+
}
37+
38+
:host(.tab--bottom) .tab {
39+
border-top: calc(var(--sl-spacing-2x-small) - var(--group-track-width)) solid transparent;
40+
padding-top: calc(var(--sl-spacing-medium) + var(--group-track-width));
41+
transition: var(--sl-transition-medium) border-color ease;
42+
}
43+
44+
:host(.tab--start) .tab {
45+
display: flex;
46+
border-right: calc(var(--sl-spacing-2x-small) - var(--group-track-width)) solid transparent;
47+
padding-right: calc(var(--sl-spacing-medium) + var(--group-track-width));
48+
transition: var(--sl-transition-medium) border-color ease;
49+
}
50+
51+
:host(.tab--end) .tab {
52+
border-left: calc(var(--sl-spacing-2x-small) - var(--group-track-width)) solid transparent;
53+
padding-left: calc(var(--sl-spacing-medium) + var(--group-track-width));
54+
transition: var(--sl-transition-medium) border-color ease;
55+
}
56+
57+
.tab:hover:not(.tab--disabled):not(.tab--active) {
58+
border-color: var(--sl-color-neutral-400);
2959
}
3060
3161
.tab:focus {
@@ -38,7 +68,7 @@ export default css`
3868
3969
.tab:focus-visible {
4070
outline: var(--sl-focus-ring);
41-
outline-offset: calc(-1 * var(--sl-focus-ring-width) - var(--sl-focus-ring-offset));
71+
outline-offset: calc(-1 * var(--sl-focus-ring-width));
4272
}
4373
4474
.tab.tab--active:not(.tab--disabled) {

0 commit comments

Comments
 (0)