@oslokommune/punkt-react 16.8.1 → 16.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/index.d.ts +2 -0
- package/dist/punkt-react.es.js +141 -69
- package/dist/punkt-react.umd.js +20 -17
- package/package.json +4 -4
- package/src/components/tabs/TabItem.tsx +35 -7
- package/src/components/tabs/Tabs.test.tsx +107 -9
- package/src/components/tabs/Tabs.tsx +55 -14
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
## [16.8.2](https://github.com/oslokommune/punkt/compare/16.8.1...16.8.2) (2026-04-21)
|
|
9
|
+
|
|
10
|
+
### ⚠ BREAKING CHANGES
|
|
11
|
+
Ingen
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
Ingen
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
Ingen
|
|
18
|
+
|
|
19
|
+
### Chores
|
|
20
|
+
Ingen
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
|
|
8
25
|
## [16.8.1](https://github.com/oslokommune/punkt/compare/16.8.0...16.8.1) (2026-04-17)
|
|
9
26
|
|
|
10
27
|
### ⚠ BREAKING CHANGES
|
package/dist/index.d.ts
CHANGED
|
@@ -746,6 +746,7 @@ export declare interface IPktTab {
|
|
|
746
746
|
text: string;
|
|
747
747
|
href?: string;
|
|
748
748
|
action?: (index: number) => void;
|
|
749
|
+
disabled?: boolean;
|
|
749
750
|
icon?: string;
|
|
750
751
|
controls?: string;
|
|
751
752
|
tag?: {
|
|
@@ -758,6 +759,7 @@ export declare interface IPktTab {
|
|
|
758
759
|
declare interface IPktTabItem {
|
|
759
760
|
children: ReactNode;
|
|
760
761
|
active?: boolean;
|
|
762
|
+
disabled?: boolean;
|
|
761
763
|
href?: string;
|
|
762
764
|
onClick?: (event: MouseEvent_2) => void;
|
|
763
765
|
icon?: string;
|
package/dist/punkt-react.es.js
CHANGED
|
@@ -9497,7 +9497,7 @@ try {
|
|
|
9497
9497
|
console.warn("Forsøker å definere <pkt-radiobutton>, men den er allerede definert");
|
|
9498
9498
|
}
|
|
9499
9499
|
//#endregion
|
|
9500
|
-
//#region ../elements/dist/tabs-
|
|
9500
|
+
//#region ../elements/dist/tabs-C0DWPmn2.js
|
|
9501
9501
|
var Co = class extends Event {
|
|
9502
9502
|
constructor(e, t, n, r) {
|
|
9503
9503
|
super("context-request", {
|
|
@@ -9656,7 +9656,7 @@ function Ao({ context: e, subscribe: t }) {
|
|
|
9656
9656
|
}
|
|
9657
9657
|
var jo = wo(Symbol("pkt-tabs-context")), Mo = class extends Vt {
|
|
9658
9658
|
constructor(...e) {
|
|
9659
|
-
super(...e), this.arrowNav = !0, this.disableArrowNav = !1, this.tabRefs = [], this.tabCount = 0, this.context = {
|
|
9659
|
+
super(...e), this.arrowNav = !0, this.disableArrowNav = !1, this.tabRefs = [], this.disabledMap = {}, this.tabCount = 0, this.context = {
|
|
9660
9660
|
useArrowNav: this.useArrowNav,
|
|
9661
9661
|
registerTab: this.registerTab.bind(this),
|
|
9662
9662
|
handleClick: this.handleClick.bind(this),
|
|
@@ -9672,22 +9672,41 @@ var jo = wo(Symbol("pkt-tabs-context")), Mo = class extends Vt {
|
|
|
9672
9672
|
useArrowNav: this.useArrowNav
|
|
9673
9673
|
});
|
|
9674
9674
|
}
|
|
9675
|
-
registerTab(e, t) {
|
|
9676
|
-
this.tabRefs[t] = e, this.tabCount = Math.max(this.tabCount, t + 1);
|
|
9675
|
+
registerTab(e, t, n = !1) {
|
|
9676
|
+
this.tabRefs[t] = e, this.disabledMap[t] = n, this.tabCount = Math.max(this.tabCount, t + 1);
|
|
9677
|
+
}
|
|
9678
|
+
isTabDisabled(e) {
|
|
9679
|
+
return !!this.disabledMap[e];
|
|
9680
|
+
}
|
|
9681
|
+
findEnabledIndex(e, t) {
|
|
9682
|
+
let n = e + t;
|
|
9683
|
+
for (; n >= 0 && n < this.tabCount;) {
|
|
9684
|
+
if (!this.isTabDisabled(n)) return n;
|
|
9685
|
+
n += t;
|
|
9686
|
+
}
|
|
9687
|
+
return null;
|
|
9677
9688
|
}
|
|
9678
9689
|
handleClick(e) {
|
|
9679
|
-
this.dispatchEvent(new CustomEvent("tab-selected", {
|
|
9690
|
+
this.isTabDisabled(e) || this.dispatchEvent(new CustomEvent("tab-selected", {
|
|
9680
9691
|
detail: { index: e },
|
|
9681
9692
|
bubbles: !0,
|
|
9682
9693
|
composed: !0
|
|
9683
9694
|
}));
|
|
9684
9695
|
}
|
|
9685
9696
|
handleKeyUp(e, t) {
|
|
9686
|
-
|
|
9687
|
-
|
|
9688
|
-
|
|
9689
|
-
|
|
9690
|
-
|
|
9697
|
+
if (this.useArrowNav) {
|
|
9698
|
+
if (e.key === "ArrowLeft") {
|
|
9699
|
+
e.preventDefault();
|
|
9700
|
+
let n = this.findEnabledIndex(t, -1);
|
|
9701
|
+
n !== null && this.tabRefs[n]?.focus();
|
|
9702
|
+
}
|
|
9703
|
+
if (e.key === "ArrowRight") {
|
|
9704
|
+
e.preventDefault();
|
|
9705
|
+
let n = this.findEnabledIndex(t, 1);
|
|
9706
|
+
n !== null && this.tabRefs[n]?.focus();
|
|
9707
|
+
}
|
|
9708
|
+
(e.key === "Enter" || e.key === " " || e.key === "Spacebar" || e.key === "ArrowDown") && (e.preventDefault(), this.handleClick(t));
|
|
9709
|
+
}
|
|
9691
9710
|
}
|
|
9692
9711
|
render() {
|
|
9693
9712
|
return z`
|
|
@@ -9705,7 +9724,7 @@ J([K({
|
|
|
9705
9724
|
type: Boolean,
|
|
9706
9725
|
reflect: !0,
|
|
9707
9726
|
attribute: "disable-arrow-nav"
|
|
9708
|
-
})], Mo.prototype, "disableArrowNav", void 0), J([q()], Mo.prototype, "tabRefs", void 0), J([q()], Mo.prototype, "tabCount", void 0), J([ko({ context: jo }), q()], Mo.prototype, "context", void 0);
|
|
9727
|
+
})], Mo.prototype, "disableArrowNav", void 0), J([q()], Mo.prototype, "tabRefs", void 0), J([q()], Mo.prototype, "disabledMap", void 0), J([q()], Mo.prototype, "tabCount", void 0), J([ko({ context: jo }), q()], Mo.prototype, "context", void 0);
|
|
9709
9728
|
try {
|
|
9710
9729
|
G("pkt-tabs")(Mo);
|
|
9711
9730
|
} catch {
|
|
@@ -9713,21 +9732,32 @@ try {
|
|
|
9713
9732
|
}
|
|
9714
9733
|
var No = class extends Vt {
|
|
9715
9734
|
constructor() {
|
|
9716
|
-
super(), this.active = !1, this.href = "", this.icon = "", this.controls = "", this.tag = "", this.tagSkin = "blue", this.index = 0, this.elementRef = sn();
|
|
9735
|
+
super(), this.active = !1, this.disabled = !1, this.href = "", this.icon = "", this.controls = "", this.tag = "", this.tagSkin = "blue", this.index = 0, this.elementRef = sn();
|
|
9717
9736
|
}
|
|
9718
9737
|
connectedCallback() {
|
|
9719
9738
|
super.connectedCallback(), this.updateComplete.then(() => {
|
|
9720
|
-
this.elementRef.value && this.context && this.context.registerTab(this.elementRef.value, this.index);
|
|
9739
|
+
this.elementRef.value && this.context && this.context.registerTab(this.elementRef.value, this.index, this.disabled);
|
|
9721
9740
|
});
|
|
9722
9741
|
}
|
|
9723
|
-
|
|
9742
|
+
updated() {
|
|
9743
|
+
this.elementRef.value && this.context && this.context.registerTab(this.elementRef.value, this.index, this.disabled);
|
|
9744
|
+
}
|
|
9745
|
+
handleClick(e) {
|
|
9746
|
+
if (this.disabled) {
|
|
9747
|
+
e.preventDefault(), e.stopPropagation();
|
|
9748
|
+
return;
|
|
9749
|
+
}
|
|
9724
9750
|
this.context && this.context.handleClick(this.index);
|
|
9725
9751
|
}
|
|
9726
|
-
|
|
9752
|
+
handleKeyDown(e) {
|
|
9753
|
+
if (this.disabled && (e.key === "Enter" || e.key === " " || e.key === "Spacebar")) {
|
|
9754
|
+
e.preventDefault(), e.stopPropagation();
|
|
9755
|
+
return;
|
|
9756
|
+
}
|
|
9727
9757
|
this.context && this.context.handleKeyUp(e, this.index);
|
|
9728
9758
|
}
|
|
9729
9759
|
render() {
|
|
9730
|
-
let e = this.context?.useArrowNav ?? !0, t = this.active ? "active" : "",
|
|
9760
|
+
let e = this.context?.useArrowNav ?? !0, t = this.active && !this.disabled, n = [t ? "active" : "", this.disabled ? "pkt-tabs__item--disabled" : ""].filter(Boolean).join(" "), r = e ? "tab" : void 0, i = e ? t : void 0, a = this.disabled ? -1 : t || !e ? void 0 : -1, o = z`
|
|
9731
9761
|
${this.icon ? z`<pkt-icon name=${this.icon} class="pkt-icon--small"></pkt-icon>` : ""}
|
|
9732
9762
|
<span>${Bt(this)}</span>
|
|
9733
9763
|
${this.tag ? z`<pkt-tag skin=${this.tagSkin} size="small">${this.tag}</pkt-tag>` : ""}
|
|
@@ -9735,30 +9765,33 @@ var No = class extends Vt {
|
|
|
9735
9765
|
return this.href ? z`
|
|
9736
9766
|
<a
|
|
9737
9767
|
${un(this.elementRef)}
|
|
9738
|
-
href=${this.href}
|
|
9739
|
-
class="pkt-tabs__link ${
|
|
9740
|
-
role=${X(
|
|
9741
|
-
aria-selected=${X(
|
|
9768
|
+
href=${X(this.disabled ? void 0 : this.href)}
|
|
9769
|
+
class="pkt-tabs__link ${n}"
|
|
9770
|
+
role=${X(r)}
|
|
9771
|
+
aria-selected=${X(i)}
|
|
9772
|
+
aria-disabled=${X(this.disabled ? "true" : void 0)}
|
|
9742
9773
|
aria-controls=${X(this.controls || void 0)}
|
|
9743
|
-
tabindex=${X(
|
|
9774
|
+
tabindex=${X(a)}
|
|
9744
9775
|
@click=${this.handleClick}
|
|
9745
|
-
@
|
|
9776
|
+
@keydown=${this.handleKeyDown}
|
|
9746
9777
|
>
|
|
9747
|
-
${
|
|
9778
|
+
${o}
|
|
9748
9779
|
</a>
|
|
9749
9780
|
` : z`
|
|
9750
9781
|
<button
|
|
9751
9782
|
${un(this.elementRef)}
|
|
9752
9783
|
type="button"
|
|
9753
|
-
class="pkt-tabs__button pkt-link-button ${
|
|
9754
|
-
|
|
9755
|
-
aria-
|
|
9784
|
+
class="pkt-tabs__button pkt-link-button ${n}"
|
|
9785
|
+
?disabled=${this.disabled}
|
|
9786
|
+
aria-disabled=${X(this.disabled ? "true" : void 0)}
|
|
9787
|
+
role=${X(r)}
|
|
9788
|
+
aria-selected=${X(i)}
|
|
9756
9789
|
aria-controls=${X(this.controls || void 0)}
|
|
9757
|
-
tabindex=${X(
|
|
9790
|
+
tabindex=${X(a)}
|
|
9758
9791
|
@click=${this.handleClick}
|
|
9759
|
-
@
|
|
9792
|
+
@keydown=${this.handleKeyDown}
|
|
9760
9793
|
>
|
|
9761
|
-
${
|
|
9794
|
+
${o}
|
|
9762
9795
|
</button>
|
|
9763
9796
|
`;
|
|
9764
9797
|
}
|
|
@@ -9767,6 +9800,9 @@ J([K({
|
|
|
9767
9800
|
type: Boolean,
|
|
9768
9801
|
reflect: !0
|
|
9769
9802
|
})], No.prototype, "active", void 0), J([K({
|
|
9803
|
+
type: Boolean,
|
|
9804
|
+
reflect: !0
|
|
9805
|
+
})], No.prototype, "disabled", void 0), J([K({
|
|
9770
9806
|
type: String,
|
|
9771
9807
|
reflect: !0
|
|
9772
9808
|
})], No.prototype, "href", void 0), J([K({
|
|
@@ -17073,41 +17109,54 @@ var zd = ({ className: e, compact: t = !1, skin: n = "basic", responsiveView: r
|
|
|
17073
17109
|
role: "row",
|
|
17074
17110
|
...n,
|
|
17075
17111
|
children: t
|
|
17076
|
-
}), Gd = s(({ children: e, active: t,
|
|
17077
|
-
let { arrowNav:
|
|
17078
|
-
"aria-selected":
|
|
17079
|
-
"aria-controls":
|
|
17080
|
-
role:
|
|
17081
|
-
|
|
17112
|
+
}), Gd = s(({ children: e, active: t, disabled: n = !1, href: r, onClick: i, icon: a, controls: o, tag: s, tagSkin: c, index: l = 0 }, u) => {
|
|
17113
|
+
let { arrowNav: d, registerTabRef: f, handleKeyPress: p, selectTab: m } = qd(), h = !!t && !n, g = {
|
|
17114
|
+
"aria-selected": d ? h : void 0,
|
|
17115
|
+
"aria-controls": o,
|
|
17116
|
+
role: d ? "tab" : void 0,
|
|
17117
|
+
onKeyDown: (e) => {
|
|
17118
|
+
if (n && (e.key === "Enter" || e.key === " " || e.key === "Spacebar")) {
|
|
17119
|
+
e.preventDefault(), e.stopPropagation();
|
|
17120
|
+
return;
|
|
17121
|
+
}
|
|
17122
|
+
p(l, e);
|
|
17123
|
+
},
|
|
17082
17124
|
onClick: (e) => {
|
|
17083
|
-
|
|
17125
|
+
if (n) {
|
|
17126
|
+
e.preventDefault(), e.stopPropagation();
|
|
17127
|
+
return;
|
|
17128
|
+
}
|
|
17129
|
+
m(l), i?.(e);
|
|
17084
17130
|
},
|
|
17085
|
-
tabIndex:
|
|
17131
|
+
tabIndex: n ? -1 : h || !d ? void 0 : -1,
|
|
17086
17132
|
ref: (e) => {
|
|
17087
|
-
|
|
17133
|
+
f(l, e, n), typeof u == "function" ? u(e) : u && (u.current = e);
|
|
17088
17134
|
}
|
|
17089
|
-
},
|
|
17090
|
-
|
|
17091
|
-
name:
|
|
17135
|
+
}, _ = /* @__PURE__ */ b(v, { children: [
|
|
17136
|
+
a && /* @__PURE__ */ y(Q, {
|
|
17137
|
+
name: a,
|
|
17092
17138
|
className: "pkt-icon--small"
|
|
17093
17139
|
}),
|
|
17094
17140
|
e,
|
|
17095
|
-
|
|
17096
|
-
skin:
|
|
17141
|
+
s && /* @__PURE__ */ y(dl, {
|
|
17142
|
+
skin: c,
|
|
17097
17143
|
size: "small",
|
|
17098
|
-
children:
|
|
17144
|
+
children: s
|
|
17099
17145
|
})
|
|
17100
17146
|
] });
|
|
17101
|
-
return
|
|
17102
|
-
...
|
|
17103
|
-
href: n,
|
|
17104
|
-
|
|
17105
|
-
|
|
17147
|
+
return r ? /* @__PURE__ */ y("a", {
|
|
17148
|
+
...g,
|
|
17149
|
+
href: n ? void 0 : r,
|
|
17150
|
+
"aria-disabled": n || void 0,
|
|
17151
|
+
className: `pkt-tabs__link ${h ? "active" : ""} ${n ? "pkt-tabs__item--disabled" : ""}`,
|
|
17152
|
+
children: _
|
|
17106
17153
|
}) : /* @__PURE__ */ y("button", {
|
|
17107
|
-
...
|
|
17154
|
+
...g,
|
|
17108
17155
|
type: "button",
|
|
17109
|
-
|
|
17110
|
-
|
|
17156
|
+
disabled: n,
|
|
17157
|
+
"aria-disabled": n || void 0,
|
|
17158
|
+
className: `pkt-tabs__button pkt-link-button ${h ? "active" : ""} ${n ? "pkt-tabs__item--disabled" : ""}`,
|
|
17159
|
+
children: _
|
|
17111
17160
|
});
|
|
17112
17161
|
});
|
|
17113
17162
|
Gd.displayName = "PktTabItem";
|
|
@@ -17118,21 +17167,44 @@ var Kd = i(null), qd = () => {
|
|
|
17118
17167
|
if (!e) throw Error("TabItem must be used within a Tabs component");
|
|
17119
17168
|
return e;
|
|
17120
17169
|
}, Jd = s(({ arrowNav: e = !0, disableArrowNav: n = !1, tabs: r, onTabSelected: i, children: a }, o) => {
|
|
17121
|
-
let s = g([]), c = e && !n,
|
|
17170
|
+
let s = g([]), c = g({}), l = e && !n, u = a && t.count(a) > 0 ? t.count(a) : r?.length || 0;
|
|
17122
17171
|
d(() => {
|
|
17123
|
-
s.current = s.current.slice(0,
|
|
17124
|
-
|
|
17125
|
-
|
|
17172
|
+
s.current = s.current.slice(0, u), Object.keys(c.current).forEach((e) => {
|
|
17173
|
+
let t = Number(e);
|
|
17174
|
+
t >= u && delete c.current[t];
|
|
17175
|
+
});
|
|
17176
|
+
}, [u]);
|
|
17177
|
+
let f = (e) => r ? !!r[e]?.disabled : !!c.current[e], p = (e) => {
|
|
17178
|
+
if (f(e)) return;
|
|
17126
17179
|
let t = r?.[e];
|
|
17127
17180
|
t?.action && t.action(e), i && i(e);
|
|
17128
|
-
},
|
|
17129
|
-
|
|
17130
|
-
|
|
17131
|
-
|
|
17132
|
-
|
|
17133
|
-
|
|
17181
|
+
}, m = (e, t) => {
|
|
17182
|
+
let n = e + t;
|
|
17183
|
+
for (; n >= 0 && n < u;) {
|
|
17184
|
+
if (!f(n)) return n;
|
|
17185
|
+
n += t;
|
|
17186
|
+
}
|
|
17187
|
+
return null;
|
|
17188
|
+
}, h = (e, t) => {
|
|
17189
|
+
if (l) {
|
|
17190
|
+
if (t.key === "ArrowLeft") {
|
|
17191
|
+
t.preventDefault();
|
|
17192
|
+
let n = m(e, -1);
|
|
17193
|
+
n !== null && s.current[n]?.focus();
|
|
17194
|
+
}
|
|
17195
|
+
if (t.key === "ArrowRight") {
|
|
17196
|
+
t.preventDefault();
|
|
17197
|
+
let n = m(e, 1);
|
|
17198
|
+
n !== null && s.current[n]?.focus();
|
|
17199
|
+
}
|
|
17200
|
+
(t.key === "Enter" || t.key === " " || t.key === "Spacebar" || t.key === "ArrowDown") && (t.preventDefault(), f(e) || p(e));
|
|
17201
|
+
}
|
|
17202
|
+
}, _ = (e, t, n = !1) => {
|
|
17203
|
+
s.current[e] = t, c.current[e] = n;
|
|
17204
|
+
}, v = r?.map((e, t) => /* @__PURE__ */ y(Gd, {
|
|
17205
|
+
active: e.disabled ? !1 : e.active,
|
|
17206
|
+
disabled: e.disabled,
|
|
17134
17207
|
href: e.href,
|
|
17135
|
-
onClick: () => u(t),
|
|
17136
17208
|
icon: e.icon,
|
|
17137
17209
|
controls: e.controls,
|
|
17138
17210
|
tag: e.tag?.text,
|
|
@@ -17142,18 +17214,18 @@ var Kd = i(null), qd = () => {
|
|
|
17142
17214
|
}, t));
|
|
17143
17215
|
return /* @__PURE__ */ y(Kd.Provider, {
|
|
17144
17216
|
value: {
|
|
17145
|
-
arrowNav:
|
|
17146
|
-
registerTabRef:
|
|
17147
|
-
handleKeyPress:
|
|
17148
|
-
selectTab:
|
|
17217
|
+
arrowNav: l,
|
|
17218
|
+
registerTabRef: _,
|
|
17219
|
+
handleKeyPress: h,
|
|
17220
|
+
selectTab: p
|
|
17149
17221
|
},
|
|
17150
17222
|
children: /* @__PURE__ */ y("div", {
|
|
17151
17223
|
className: "pkt-tabs",
|
|
17152
17224
|
ref: o,
|
|
17153
17225
|
children: /* @__PURE__ */ y("div", {
|
|
17154
17226
|
className: "pkt-tabs__list",
|
|
17155
|
-
role:
|
|
17156
|
-
children: a ||
|
|
17227
|
+
role: l ? "tablist" : "navigation",
|
|
17228
|
+
children: a || v
|
|
17157
17229
|
})
|
|
17158
17230
|
})
|
|
17159
17231
|
});
|