Skip to content

Commit 274078f

Browse files
committed
Bug fixes.
1 parent 5b072f6 commit 274078f

File tree

6 files changed

+73
-64
lines changed

6 files changed

+73
-64
lines changed

src/pg/icon/__examples__/basic/basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default class XPgIconBasic extends HTMLElement {
2121
}
2222

2323
handleClear() {
24-
this.$icon1.path = '';
24+
this.$icon1.path = 'M0 0h24v24H0V0zm2 2v20h20V2H2z';
2525
}
2626

2727
handleAccount() {

src/pg/icon/icon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class PgIcon extends HTMLElement {
2020
if (changes.path) {
2121
const viewBox = getComputedStyle(this).getPropertyValue('--pg-icon-viewbox');
2222
this.$svg.setAttribute('viewBox', viewBox || '0 0 24 24');
23-
if (!this.path) {
23+
if (this.path) {
2424
throw new Error('invalid path set on pg-icon');
2525
}
2626
this.$path.setAttribute('d', this.path);

src/pg/tabs/partials/tab.css

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
[part="button"] {
3+
position: relative;
4+
display: flex;
5+
line-height: calc(2.5rem - 0.5px);
6+
border-top: 1px solid transparent;
7+
border-right: 1px solid transparent;
8+
border-bottom: 0;
9+
border-left: 1px solid transparent;
10+
border-radius: 0.25rem 0.25rem 0 0;
11+
padding: 0 0.75rem;
12+
text-decoration: none;
13+
color: var(--pg-tab-border, #453C4F);
14+
align-items: center;
15+
align-content: center;
16+
box-sizing: border-box;
17+
outline: none;
18+
background: transparent;
19+
}
20+
21+
[part="button"].selected {
22+
border-color: var(--pg-tab-border, #453C4F);
23+
font-weight: bold;
24+
background: #fff;
25+
cursor: default;
26+
height: calc(2.5rem + 0.5px);
27+
}
28+
29+
[part="button"]:not(.selected):hover {
30+
border-color: var(--pg-tab-border, #453C4F);
31+
}
32+
33+
[part="button"]:active::before {
34+
content: '';
35+
position: absolute;
36+
top: -1px;
37+
right: -1px;
38+
bottom: 0;
39+
left: -1px;
40+
border-radius: 0.25rem 0.25rem 0 0;
41+
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.6));
42+
}
43+
44+
[part="button"]:focus::before {
45+
pointer-events: none;
46+
content: '';
47+
position: absolute;
48+
top: -1px;
49+
right: -1px;
50+
bottom: 0;
51+
left: -1px;
52+
border-radius: 0.25rem 0.25rem 0 0;
53+
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.5));
54+
}

src/pg/tabs/partials/tab.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Component, Prop, Part, node, forEach } from '@pictogrammers/element';
22

33
import template from './tab.html';
4+
import style from './tab.css';
45

56
@Component({
67
selector: 'pg-partial-tab',
7-
template
8+
template,
9+
style
810
})
911
export default class PgPartialTab extends HTMLElement {
1012

@@ -47,6 +49,7 @@ export default class PgPartialTab extends HTMLElement {
4749
}
4850
});
4951
this.dispatchEvent(arrowLeftEvent);
52+
e.preventDefault();
5053
break;
5154
case 'ArrowRight':
5255
const arrowRightEvent = new CustomEvent('arrowright', {
@@ -55,6 +58,7 @@ export default class PgPartialTab extends HTMLElement {
5558
}
5659
});
5760
this.dispatchEvent(arrowRightEvent);
61+
e.preventDefault();
5862
break;
5963
}
6064
}

src/pg/tabs/tabs.css

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,3 @@
1414
[part="tab"] {
1515
margin-right: 0.25rem;
1616
}
17-
18-
[part="button"] {
19-
position: relative;
20-
display: flex;
21-
line-height: calc(2.5rem - 0.5px);
22-
border-top: 1px solid transparent;
23-
border-right: 1px solid transparent;
24-
border-bottom: 0;
25-
border-left: 1px solid transparent;
26-
border-radius: 0.25rem 0.25rem 0 0;
27-
padding: 0 0.75rem;
28-
text-decoration: none;
29-
color: var(--pg-tab-border, #453C4F);
30-
align-items: center;
31-
align-content: center;
32-
box-sizing: border-box;
33-
outline: none;
34-
background: transparent;
35-
}
36-
37-
[part="tab"].active [part="button"] {
38-
border-color: var(--pg-tab-border, #453C4F);
39-
font-weight: bold;
40-
background: #fff;
41-
cursor: default;
42-
height: calc(2.5rem + 0.5px);
43-
}
44-
45-
[part="button"]:not(.active):hover {
46-
border-color: var(--pg-tab-border, #453C4F);
47-
}
48-
49-
[part="button"]:active::before {
50-
content: '';
51-
position: absolute;
52-
top: -1px;
53-
right: -1px;
54-
bottom: 0;
55-
left: -1px;
56-
border-radius: 0.25rem 0.25rem 0 0;
57-
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.6));
58-
}
59-
60-
[part="button"]:focus::before {
61-
pointer-events: none;
62-
content: '';
63-
position: absolute;
64-
top: -1px;
65-
right: -1px;
66-
bottom: 0;
67-
left: -1px;
68-
border-radius: 0.25rem 0.25rem 0 0;
69-
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.5));
70-
}

src/pg/tabs/tabs.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class PgTabs extends HTMLElement {
1919
#tabs: any[] = [];
2020

2121
#selectedTab: number = 0;
22+
#focusedTab: number = 0;
2223

2324
connectedCallback() {
2425
this.addEventListener('tab', this.#handleTab.bind(this));
@@ -36,29 +37,31 @@ export default class PgTabs extends HTMLElement {
3637
console.log(index, this.#tabs[e.detail.index]);
3738
const elements = this.$slot.assignedElements() as PgTab[];
3839
elements[this.#selectedTab].hide();
40+
$tabs[this.#selectedTab].selected = false;
3941
elements[index].show();
42+
$tabs[index].selected = true;
4043
this.#selectedTab = index;
4144
});
42-
$tab.addEventListener('arrowleft', (e: any) => {
45+
$tab.addEventListener('arrowleft', (e: any) => {
4346
const { index } = e.detail;
4447
if (this.#tabs.length > 1) {
4548
if (index === 0) {
46-
this.#selectedTab = this.#tabs.length - 1;
49+
this.#focusedTab = this.#tabs.length - 1;
4750
} else {
48-
this.#selectedTab = index - 1;
51+
this.#focusedTab = index - 1;
4952
}
50-
$tabs[this.#selectedTab].focus();
53+
$tabs[this.#focusedTab].focus();
5154
}
5255
});
5356
$tab.addEventListener('arrowright', (e: any) => {
5457
const { index } = e.detail;
5558
if (this.#tabs.length > 1) {
5659
if (index === this.#tabs.length - 1) {
57-
this.#selectedTab = 0;
60+
this.#focusedTab = 0;
5861
} else {
59-
this.#selectedTab++;
62+
this.#focusedTab++;
6063
}
61-
$tabs[this.#selectedTab].focus();
64+
$tabs[this.#focusedTab].focus();
6265
}
6366
});
6467
}
@@ -72,9 +75,11 @@ export default class PgTabs extends HTMLElement {
7275
}
7376

7477
handleSlotChange(e) {
78+
const tabs = Array.from(this.$tabset.children) as PgPartialTab[];
7579
const elements = this.$slot.assignedElements() as PgTab[];
7680
if (elements.length !== 0) {
7781
elements[0].show();
82+
tabs[0].selected = true;
7883
}
7984
}
8085

0 commit comments

Comments
 (0)