@oslokommune/punkt-elements 18.9.3 → 18.9.7
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 +34 -0
- package/dist/{accordion-CsrLQXEA.cjs → accordion-BLMbI8SQ.cjs} +1 -1
- package/dist/{accordion-DoxhiwK-.js → accordion-Bwka5Mxo.js} +5 -5
- package/dist/{alert-DH3VqNqh.cjs → alert-Cfr6t5uz.cjs} +1 -1
- package/dist/{alert-DxAGxSX_.js → alert-DaXpwnzT.js} +6 -6
- package/dist/{async-directive-BSwJ8-GL.js → async-directive-C8UAk8Mv.js} +2 -2
- package/dist/{async-directive-CfPXShXu.cjs → async-directive-U0EE5r36.cjs} +1 -1
- package/dist/{backlink-CGc7r9CS.js → backlink-BjJwDjuP.js} +3 -3
- package/dist/{backlink-CDH824db.cjs → backlink-DM220m4q.cjs} +1 -1
- package/dist/{breadcrumbs-DRGhIXmN.js → breadcrumbs-B1pDtQy8.js} +2 -2
- package/dist/{breadcrumbs-B37tsIoh.cjs → breadcrumbs-BUmbj-hP.cjs} +1 -1
- package/dist/{button-D6QhHPWH.js → button-BUl8uWWh.js} +5 -5
- package/dist/{button-Cx6Xdp6t.cjs → button-CCR4eyt_.cjs} +1 -1
- package/dist/{calendar-CAwIY7x_.cjs → calendar-BuSfyUR9.cjs} +1 -1
- package/dist/{calendar-42o_q-jI.js → calendar-KUQ1dFeX.js} +3 -3
- package/dist/{card-cyZE94EO.js → card-27RxxKxW.js} +6 -6
- package/dist/{card-CB72gwBC.cjs → card-B-RKnu_C.cjs} +1 -1
- package/dist/{checkbox-BhyUp6l6.js → checkbox-CTf4GatI.js} +4 -4
- package/dist/{checkbox-DJfH-vTj.cjs → checkbox-DlzVGBum.cjs} +1 -1
- package/dist/{class-map-DupQbnhE.cjs → class-map-B0FX3YsK.cjs} +1 -1
- package/dist/{class-map-DSoj1J68.js → class-map-D5GHsely.js} +1 -1
- package/dist/combobox-CNCM-Psm.cjs +139 -0
- package/dist/{combobox-fzSaCPok.js → combobox-Dym_phvv.js} +67 -58
- package/dist/components/combobox/combobox.d.ts +1 -0
- package/dist/components/header/header-service.d.ts +1 -1
- package/dist/components/header/types.d.ts +1 -1
- package/dist/components/helptext/helptext-association.test.d.ts +0 -0
- package/dist/components/timepicker/timepicker.d.ts +1 -0
- package/dist/{consent-CsgKWDsR.js → consent-BeoP4rOa.js} +2 -2
- package/dist/{consent-DnE6IPEj.cjs → consent-Cle1hkPg.cjs} +1 -1
- package/dist/{datepicker-D6os8IVu.cjs → datepicker-BtEZMsWH.cjs} +1 -1
- package/dist/{datepicker-DMiZ3BBw.js → datepicker-Ct4dbs4e.js} +11 -11
- package/dist/{directive-helpers-2mcpDDv5.cjs → directive-helpers-BushnrQQ.cjs} +1 -1
- package/dist/{directive-helpers-ChEduoup.js → directive-helpers-DpyLJPJm.js} +1 -1
- package/dist/{element-D_mCyFeX.cjs → element-CewjrA4g.cjs} +1 -1
- package/dist/{element-J8nynuVk.js → element-CqC-sGuC.js} +11 -1
- package/dist/{element-with-slot-BOuXlWSY.js → element-with-slot-D_OKDlYo.js} +2 -2
- package/dist/{element-with-slot-C66Jck5e.cjs → element-with-slot-MCvSBwUv.cjs} +1 -1
- package/dist/{fileupload-Y4bDkaD9.cjs → fileupload-BVAgrofy.cjs} +3 -3
- package/dist/{fileupload-C5lxuood.js → fileupload-Dqf_94m2.js} +11 -11
- package/dist/{footer-ByAxlj9_.js → footer-Bf6RFuia.js} +4 -4
- package/dist/{footer-Ca3DM544.cjs → footer-XrX6LFHY.cjs} +1 -1
- package/dist/{header-CP332MCg.cjs → header-DMMt5FtF.cjs} +64 -50
- package/dist/{header-CCJeadiL.js → header-fkKhLsyE.js} +182 -167
- package/dist/{header-menu-CIuu8_UC.js → header-menu-CUHrJCvx.js} +4 -4
- package/dist/{header-menu-B9ABa0WW.cjs → header-menu-DYZsigfH.cjs} +1 -1
- package/dist/{heading-4ZHACOeL.cjs → heading-BDdX4JiM.cjs} +1 -1
- package/dist/{heading-BHWdVbvN.js → heading-ELXWxyTv.js} +2 -2
- package/dist/{helptext-BESB9Vlq.js → helptext-BQkrYsoV.js} +4 -4
- package/dist/{helptext-6HsH-I6a.cjs → helptext-DQe6GO75.cjs} +1 -1
- package/dist/{icon-DkVqRWbC.js → icon-B2v30QUk.js} +1 -1
- package/dist/{icon-BzxBkRyE.cjs → icon-Clz68-Kz.cjs} +1 -1
- package/dist/{if-defined-BILLSM7i.js → if-defined-BNXGXCwT.js} +1 -1
- package/dist/if-defined-CjRKmMQs.cjs +1 -0
- package/dist/{input-element-BWxgs8L-.js → input-element-BTzuDh4h.js} +2 -2
- package/dist/{input-element-PN5nWd1A.cjs → input-element-BdIWsDl-.cjs} +1 -1
- package/dist/{input-wrapper-D64Qn-QH.cjs → input-wrapper-BIrQijWT.cjs} +1 -1
- package/dist/{input-wrapper-Bg06k-cj.js → input-wrapper-CvFMiqIt.js} +6 -6
- package/dist/{link-Bk7aDZCC.cjs → link-1JEWpEDG.cjs} +1 -1
- package/dist/{link-C7fOEv66.js → link-BxKWhYsn.js} +4 -4
- package/dist/{linkcard-Bguo9oCv.js → linkcard-CICSZ7pK.js} +4 -4
- package/dist/{linkcard-rZpQuO1Z.cjs → linkcard-DXOkeQUy.cjs} +1 -1
- package/dist/{listbox-CrQboPG6.js → listbox-DcCrI15L.js} +4 -4
- package/dist/{listbox-kV4OO1Qa.cjs → listbox-DsYaWvLu.cjs} +1 -1
- package/dist/{loader-BAn68gBb.cjs → loader-BA__N62k.cjs} +1 -1
- package/dist/{loader-C3gwO0i3.js → loader-nIl61aTv.js} +4 -4
- package/dist/{messagebox-WH2HjT5I.cjs → messagebox-CdNMgTz4.cjs} +1 -1
- package/dist/{messagebox-DAE59dMX.js → messagebox-D0qxveug.js} +4 -4
- package/dist/{modal-DdC1_qT3.js → modal-D5tGq-nN.js} +5 -5
- package/dist/{modal-DZm_fn3K.cjs → modal-i3Qxv38H.cjs} +1 -1
- package/dist/pkt-accordion.cjs +1 -1
- package/dist/pkt-accordion.js +1 -1
- package/dist/pkt-alert.cjs +1 -1
- package/dist/pkt-alert.js +1 -1
- package/dist/pkt-backlink.cjs +1 -1
- package/dist/pkt-backlink.js +1 -1
- package/dist/pkt-breadcrumbs.cjs +1 -1
- package/dist/pkt-breadcrumbs.js +1 -1
- package/dist/pkt-button.cjs +1 -1
- package/dist/pkt-button.js +1 -1
- package/dist/pkt-calendar.cjs +1 -1
- package/dist/pkt-calendar.js +1 -1
- package/dist/pkt-card.cjs +1 -1
- package/dist/pkt-card.js +1 -1
- package/dist/pkt-checkbox.cjs +1 -1
- package/dist/pkt-checkbox.js +1 -1
- package/dist/pkt-combobox.cjs +1 -1
- package/dist/pkt-combobox.js +1 -1
- package/dist/pkt-consent.cjs +1 -1
- package/dist/pkt-consent.js +1 -1
- package/dist/pkt-datepicker.cjs +1 -1
- package/dist/pkt-datepicker.js +1 -1
- package/dist/pkt-fileupload.cjs +1 -1
- package/dist/pkt-fileupload.js +1 -1
- package/dist/pkt-footer.cjs +1 -1
- package/dist/pkt-footer.js +1 -1
- package/dist/pkt-header-menu.cjs +1 -1
- package/dist/pkt-header-menu.js +1 -1
- package/dist/pkt-header.cjs +1 -1
- package/dist/pkt-header.js +1 -1
- package/dist/pkt-heading.cjs +1 -1
- package/dist/pkt-heading.js +1 -1
- package/dist/pkt-helptext.cjs +1 -1
- package/dist/pkt-helptext.js +1 -1
- package/dist/pkt-icon.cjs +1 -1
- package/dist/pkt-icon.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +34 -34
- package/dist/pkt-input-wrapper.cjs +1 -1
- package/dist/pkt-input-wrapper.js +1 -1
- package/dist/pkt-link.cjs +1 -1
- package/dist/pkt-link.js +1 -1
- package/dist/pkt-linkcard.cjs +1 -1
- package/dist/pkt-linkcard.js +1 -1
- package/dist/pkt-listbox.cjs +1 -1
- package/dist/pkt-listbox.js +1 -1
- package/dist/pkt-loader.cjs +1 -1
- package/dist/pkt-loader.js +1 -1
- package/dist/pkt-messagebox.cjs +1 -1
- package/dist/pkt-messagebox.js +1 -1
- package/dist/pkt-modal.cjs +1 -1
- package/dist/pkt-modal.js +1 -1
- package/dist/{pkt-options-controller-DXAAVcBJ.cjs → pkt-options-controller-BClk341e.cjs} +1 -1
- package/dist/{pkt-options-controller-XcIgx_v1.js → pkt-options-controller-v2bPM9iU.js} +1 -1
- package/dist/pkt-progressbar.cjs +1 -1
- package/dist/pkt-progressbar.js +1 -1
- package/dist/pkt-radiobutton.cjs +1 -1
- package/dist/pkt-radiobutton.js +1 -1
- package/dist/pkt-searchinput.cjs +1 -1
- package/dist/pkt-searchinput.js +1 -1
- package/dist/pkt-select.cjs +1 -1
- package/dist/pkt-select.js +1 -1
- package/dist/pkt-tabs.cjs +1 -1
- package/dist/pkt-tabs.js +1 -1
- package/dist/pkt-tag.cjs +1 -1
- package/dist/pkt-tag.js +1 -1
- package/dist/pkt-textarea.cjs +1 -1
- package/dist/pkt-textarea.js +1 -1
- package/dist/pkt-textinput.cjs +1 -1
- package/dist/pkt-textinput.js +1 -1
- package/dist/pkt-timepicker.cjs +1 -1
- package/dist/pkt-timepicker.js +1 -1
- package/dist/{progressbar-D1x6MwdY.js → progressbar-4WyR4T72.js} +5 -5
- package/dist/{progressbar-DsE4-qaW.cjs → progressbar-CJFGbev-.cjs} +1 -1
- package/dist/{radiobutton-CnGhAnjp.cjs → radiobutton-BQRtv7PK.cjs} +1 -1
- package/dist/{radiobutton-DWdn1O48.js → radiobutton-D7308uCY.js} +4 -4
- package/dist/{ref-DNowxdYH.js → ref-37-yxmc4.js} +2 -2
- package/dist/{ref-AuNEkS5a.cjs → ref-HT6KRjxp.cjs} +1 -1
- package/dist/{repeat-B3ksuY2F.cjs → repeat-Ddge5HTp.cjs} +1 -1
- package/dist/{repeat-CZ1oMXnW.js → repeat-DntD73oB.js} +2 -2
- package/dist/{searchinput-vi7twt5b.cjs → searchinput-D1cJ73Ki.cjs} +1 -1
- package/dist/{searchinput-CmyWnNr6.js → searchinput-j4IvYRzj.js} +4 -4
- package/dist/{select-CM-CcWab.js → select-B4gbFOil.js} +7 -7
- package/dist/{select-D761TXmv.cjs → select-oIF7UVvV.cjs} +1 -1
- package/dist/shared-strings/nb.d.ts +10 -0
- package/dist/{tabs-hiTrWsXq.cjs → tabs-95BpwB6j.cjs} +1 -1
- package/dist/{tabs-kxsX1ZEf.js → tabs-DexV26qJ.js} +4 -4
- package/dist/{tag-CGlxtBOH.cjs → tag-CQEyjF32.cjs} +1 -1
- package/dist/{tag-bztxjcF0.js → tag-DoUC99hn.js} +5 -5
- package/dist/{textarea-D3SeDZ1r.js → textarea-DGSMKcqK.js} +9 -9
- package/dist/{textarea-4s_SiG0_.cjs → textarea-DNFX958g.cjs} +1 -1
- package/dist/{textinput-uDRbleIa.cjs → textinput-Bzkdo2mN.cjs} +1 -1
- package/dist/{textinput-Dje0Zcsa.js → textinput-DpLeElI_.js} +8 -8
- package/dist/{timepicker--CrfIU_7.js → timepicker-CCNQeX5Q.js} +36 -27
- package/dist/timepicker-DCzhlRuc.cjs +198 -0
- package/package.json +2 -2
- package/src/components/combobox/combobox.ts +12 -0
- package/src/components/fileupload/fileupload.ts +1 -3
- package/src/components/header/header-global.test.ts +8 -0
- package/src/components/header/header-global.ts +13 -2
- package/src/components/header/header-service.test.ts +54 -0
- package/src/components/header/header-service.ts +20 -7
- package/src/components/header/header-user-menu.ts +10 -8
- package/src/components/header/types.ts +3 -2
- package/src/components/helptext/helptext-association.test.ts +108 -0
- package/src/components/timepicker/timepicker.ts +11 -0
- package/dist/combobox-B9Qo7hbt.cjs +0 -137
- package/dist/if-defined-BbUZeoaQ.cjs +0 -1
- package/dist/timepicker-auQ5Y6Et.cjs +0 -196
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import '@testing-library/jest-dom'
|
|
2
2
|
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
3
|
+
import { resetPktStrings, setPktStrings } from 'shared-strings'
|
|
3
4
|
import { createElementTest, BaseTestConfig } from '../../tests/test-framework'
|
|
4
5
|
import { CustomElementFor } from '../../tests/component-registry'
|
|
5
6
|
import './header-service'
|
|
@@ -142,6 +143,59 @@ describe('pkt-header-service', () => {
|
|
|
142
143
|
expect(logoLink).toBeTruthy()
|
|
143
144
|
expect(logoLink?.getAttribute('href')).toBe('https://www.oslo.kommune.no')
|
|
144
145
|
})
|
|
146
|
+
|
|
147
|
+
it('renders logo without a link when logo-link is empty', async () => {
|
|
148
|
+
const { element } = await createHeaderServiceTest({
|
|
149
|
+
'service-name': 'Svc',
|
|
150
|
+
'logo-link': '',
|
|
151
|
+
})
|
|
152
|
+
const logo = element.querySelector('.pkt-header-service__logo')
|
|
153
|
+
expect(logo).toBeTruthy()
|
|
154
|
+
expect(logo?.querySelector('a')).toBeNull()
|
|
155
|
+
expect(logo?.getAttribute('role')).toBe('img')
|
|
156
|
+
expect(logo?.getAttribute('aria-label')).toBe('Oslo kommune')
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
describe('strings', () => {
|
|
161
|
+
afterEach(() => resetPktStrings())
|
|
162
|
+
|
|
163
|
+
it('labels the logo link from the string catalogue', async () => {
|
|
164
|
+
const { element } = await createHeaderServiceTest({ 'service-name': 'Svc' })
|
|
165
|
+
const logoLink = element.querySelector('.pkt-header-service__logo a')
|
|
166
|
+
expect(logoLink?.getAttribute('aria-label')).toBe('Til Oslo kommunes hovednettsted')
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it('uses the overridden logo label', async () => {
|
|
170
|
+
setPktStrings({ header: { logoLabel: 'To the front page', logoAlt: 'City of Oslo' } })
|
|
171
|
+
const { element } = await createHeaderServiceTest({ 'service-name': 'Svc' })
|
|
172
|
+
expect(element.querySelector('.pkt-header-service__logo a')?.getAttribute('aria-label')).toBe(
|
|
173
|
+
'To the front page',
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
const { element: withoutLink } = await createHeaderServiceTest({
|
|
177
|
+
'service-name': 'Svc',
|
|
178
|
+
'logo-link': '',
|
|
179
|
+
})
|
|
180
|
+
expect(
|
|
181
|
+
withoutLink.querySelector('.pkt-header-service__logo')?.getAttribute('aria-label'),
|
|
182
|
+
).toBe('City of Oslo')
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it('passes the strings property on to the user menu', async () => {
|
|
186
|
+
const { element } = await createHeaderServiceTest({
|
|
187
|
+
'service-name': 'Svc',
|
|
188
|
+
'opened-menu': 'user',
|
|
189
|
+
})
|
|
190
|
+
element.user = { name: 'Aksel' }
|
|
191
|
+
element.strings = { header: { loggedInAs: 'Innlogget som' } }
|
|
192
|
+
await element.updateComplete
|
|
193
|
+
|
|
194
|
+
const userMenu = element.querySelector('pkt-header-user-menu')
|
|
195
|
+
expect(userMenu?.querySelector('.pkt-user-menu__label')?.textContent?.trim()).toBe(
|
|
196
|
+
'Innlogget som',
|
|
197
|
+
)
|
|
198
|
+
})
|
|
145
199
|
})
|
|
146
200
|
|
|
147
201
|
describe('serviceLink and service-click event', () => {
|
|
@@ -53,7 +53,7 @@ export class PktHeaderService extends PktElementWithSlot<IPktHeader> implements
|
|
|
53
53
|
'hide'
|
|
54
54
|
@property({ type: String, attribute: 'slot-menu-variant' })
|
|
55
55
|
slotMenuVariant: TSlotMenuVariant = 'icon-only'
|
|
56
|
-
@property({ type: String, attribute: 'slot-menu-text' }) slotMenuText
|
|
56
|
+
@property({ type: String, attribute: 'slot-menu-text' }) slotMenuText?: string
|
|
57
57
|
|
|
58
58
|
@property({ type: Boolean, attribute: 'hide-logo', converter: booleanishConverter })
|
|
59
59
|
hideLogo: Booleanish = false
|
|
@@ -345,9 +345,21 @@ export class PktHeaderService extends PktElementWithSlot<IPktHeader> implements
|
|
|
345
345
|
<pkt-icon name="oslologo" aria-hidden="true" path=${this.logoPath}></pkt-icon>
|
|
346
346
|
`
|
|
347
347
|
|
|
348
|
+
if (!this.logoLink) {
|
|
349
|
+
return html`
|
|
350
|
+
<span class="pkt-header-service__logo" role="img" aria-label=${this.headerStrings.logoAlt}>
|
|
351
|
+
${logoIcon}
|
|
352
|
+
</span>
|
|
353
|
+
`
|
|
354
|
+
}
|
|
355
|
+
|
|
348
356
|
return html`
|
|
349
357
|
<span class="pkt-header-service__logo">
|
|
350
|
-
<a
|
|
358
|
+
<a
|
|
359
|
+
href=${this.logoLink}
|
|
360
|
+
aria-label=${this.headerStrings.logoLabel}
|
|
361
|
+
@click=${this.handleLogoClick}
|
|
362
|
+
>
|
|
351
363
|
${logoIcon}
|
|
352
364
|
</a>
|
|
353
365
|
</span>
|
|
@@ -429,7 +441,7 @@ export class PktHeaderService extends PktElementWithSlot<IPktHeader> implements
|
|
|
429
441
|
aria-controls="mobile-slot-menu"
|
|
430
442
|
aria-label=${this.headerStrings.openMenu}
|
|
431
443
|
>
|
|
432
|
-
${this.slotMenuText}
|
|
444
|
+
${this.slotMenuText ?? this.headerStrings.menu}
|
|
433
445
|
</pkt-button>
|
|
434
446
|
`
|
|
435
447
|
: nothing}
|
|
@@ -437,7 +449,7 @@ export class PktHeaderService extends PktElementWithSlot<IPktHeader> implements
|
|
|
437
449
|
class=${slotContentClasses}
|
|
438
450
|
id="mobile-slot-menu"
|
|
439
451
|
role=${this.isTablet ? 'group' : nothing}
|
|
440
|
-
aria-label=${this.isTablet ?
|
|
452
|
+
aria-label=${this.isTablet ? this.headerStrings.menu : nothing}
|
|
441
453
|
@click=${this.handleSlotContentClick}
|
|
442
454
|
${ref(this.slotContentRef)}
|
|
443
455
|
>
|
|
@@ -551,13 +563,14 @@ export class PktHeaderService extends PktElementWithSlot<IPktHeader> implements
|
|
|
551
563
|
secondIconName=${this.openMenu === 'user' ? 'chevron-thin-up' : 'chevron-thin-down'}
|
|
552
564
|
@click=${() => this.handleMenuToggle('user')}
|
|
553
565
|
>
|
|
554
|
-
<span class="pkt-sr-only"
|
|
566
|
+
<span class="pkt-sr-only">${this.headerStrings.userMenuButton} </span>
|
|
555
567
|
<span translate="no">${this.representing?.name || this.user.name}</span>
|
|
556
568
|
</pkt-button>
|
|
557
569
|
${this.openMenu === 'user' && this.user
|
|
558
570
|
? html`
|
|
559
571
|
<div class=${userMenuClasses}>
|
|
560
572
|
<pkt-header-user-menu
|
|
573
|
+
.strings=${this.strings}
|
|
561
574
|
.user=${this.user}
|
|
562
575
|
formatted-last-logged-in=${this.formattedLastLoggedIn || nothing}
|
|
563
576
|
.representing=${this.representing}
|
|
@@ -610,7 +623,7 @@ export class PktHeaderService extends PktElementWithSlot<IPktHeader> implements
|
|
|
610
623
|
iconName="exit"
|
|
611
624
|
@click=${this.handleLogout}
|
|
612
625
|
>
|
|
613
|
-
|
|
626
|
+
${this.headerStrings.logOut}
|
|
614
627
|
</pkt-button>
|
|
615
628
|
`
|
|
616
629
|
: nothing}
|
|
@@ -628,7 +641,7 @@ export class PktHeaderService extends PktElementWithSlot<IPktHeader> implements
|
|
|
628
641
|
iconName="exit"
|
|
629
642
|
@click=${this.handleLogout}
|
|
630
643
|
>
|
|
631
|
-
|
|
644
|
+
${this.headerStrings.logOut}
|
|
632
645
|
</pkt-button>
|
|
633
646
|
`
|
|
634
647
|
: nothing}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
Booleanish,
|
|
12
12
|
booleanishConverter,
|
|
13
13
|
} from './types'
|
|
14
|
+
import { formatString } from 'shared-strings'
|
|
14
15
|
|
|
15
16
|
import '@/components/icon'
|
|
16
17
|
import '@/components/link'
|
|
@@ -115,20 +116,21 @@ export class PktHeaderUserMenu
|
|
|
115
116
|
|
|
116
117
|
render() {
|
|
117
118
|
const internalMenuItems = this.userMenu?.map(convertUserMenuItem)
|
|
119
|
+
const strings = this.pktStrings.get('header')
|
|
118
120
|
|
|
119
121
|
return html`
|
|
120
|
-
<nav class="pkt-user-menu" aria-label
|
|
122
|
+
<nav class="pkt-user-menu" aria-label=${strings.userMenuLabel}>
|
|
121
123
|
<ul class="pkt-user-menu__list">
|
|
122
124
|
<!-- User section -->
|
|
123
125
|
${this.user
|
|
124
126
|
? html`
|
|
125
127
|
<li class="pkt-user-menu__item">
|
|
126
|
-
<div class="pkt-user-menu__label"
|
|
128
|
+
<div class="pkt-user-menu__label">${strings.loggedInAs}</div>
|
|
127
129
|
<div class="pkt-user-menu__name" translate="no">${this.user.name}</div>
|
|
128
130
|
${this.formattedLastLoggedIn
|
|
129
131
|
? html`
|
|
130
132
|
<div class="pkt-user-menu__last-logged-in">
|
|
131
|
-
|
|
133
|
+
${strings.lastLoggedIn} <time>${this.formattedLastLoggedIn}</time>
|
|
132
134
|
</div>
|
|
133
135
|
`
|
|
134
136
|
: nothing}
|
|
@@ -147,11 +149,11 @@ export class PktHeaderUserMenu
|
|
|
147
149
|
${this.representing
|
|
148
150
|
? html`
|
|
149
151
|
<li class="pkt-user-menu__item">
|
|
150
|
-
<div class="pkt-user-menu__label"
|
|
152
|
+
<div class="pkt-user-menu__label">${strings.representing}</div>
|
|
151
153
|
<div class="pkt-user-menu__name" translate="no">${this.representing.name}</div>
|
|
152
154
|
${this.representing.orgNumber
|
|
153
155
|
? html`<div class="pkt-user-menu__org-number">
|
|
154
|
-
|
|
156
|
+
${formatString(strings.orgNumber, { number: this.representing.orgNumber })}
|
|
155
157
|
</div>`
|
|
156
158
|
: nothing}
|
|
157
159
|
${this.canChangeRepresentation
|
|
@@ -159,7 +161,7 @@ export class PktHeaderUserMenu
|
|
|
159
161
|
<ul class="pkt-user-menu__sublist mt-size-16">
|
|
160
162
|
<li class="pkt-user-menu__subitem">
|
|
161
163
|
${this.renderLinkOrButton({
|
|
162
|
-
title:
|
|
164
|
+
title: strings.changeRepresentation,
|
|
163
165
|
iconName: 'cogwheel',
|
|
164
166
|
onClick: () => this.handleChangeRepresentation(),
|
|
165
167
|
})}
|
|
@@ -178,7 +180,7 @@ export class PktHeaderUserMenu
|
|
|
178
180
|
<ul class="pkt-user-menu__sublist">
|
|
179
181
|
<li class="pkt-user-menu__subitem">
|
|
180
182
|
${this.renderLinkOrButton({
|
|
181
|
-
title:
|
|
183
|
+
title: strings.changeRepresentation,
|
|
182
184
|
iconName: 'cogwheel',
|
|
183
185
|
onClick: () => this.handleChangeRepresentation(),
|
|
184
186
|
})}
|
|
@@ -193,7 +195,7 @@ export class PktHeaderUserMenu
|
|
|
193
195
|
? html`
|
|
194
196
|
<li class="pkt-user-menu__item">
|
|
195
197
|
${this.renderLinkOrButton({
|
|
196
|
-
title:
|
|
198
|
+
title: strings.logOut,
|
|
197
199
|
iconName: 'exit',
|
|
198
200
|
onClick: () => this.handleLogout(),
|
|
199
201
|
})}
|
|
@@ -55,7 +55,7 @@ export const convertUserMenuItem = (item: UserMenuItem): TInternalMenuItem => {
|
|
|
55
55
|
export interface IPktHeader extends IPktStringsProps<'header'> {
|
|
56
56
|
/** Hide the Oslo logo */
|
|
57
57
|
hideLogo?: Booleanish
|
|
58
|
-
/** Logo link URL */
|
|
58
|
+
/** Logo link URL. Set to an empty string to render the logo without a link */
|
|
59
59
|
logoLink?: string
|
|
60
60
|
/** Override CDN path for the logo */
|
|
61
61
|
logoPath?: string
|
|
@@ -110,7 +110,8 @@ export interface IPktHeader extends IPktStringsProps<'header'> {
|
|
|
110
110
|
* signal.
|
|
111
111
|
*/
|
|
112
112
|
export interface IPktHeaderGlobal
|
|
113
|
-
extends
|
|
113
|
+
extends
|
|
114
|
+
Omit<
|
|
114
115
|
ISharedPktHeaderGlobal,
|
|
115
116
|
'showSearch' | 'showContact' | 'canChangeRepresentation' | 'userMenu'
|
|
116
117
|
>,
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import '@testing-library/jest-dom'
|
|
2
|
+
import '@/components/textinput'
|
|
3
|
+
import '@/components/textarea'
|
|
4
|
+
import '@/components/select'
|
|
5
|
+
import '@/components/combobox'
|
|
6
|
+
import '@/components/datepicker'
|
|
7
|
+
import '@/components/timepicker'
|
|
8
|
+
import '@/components/fileupload'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The helptext must describe the control itself. `aria-describedby` on a label or
|
|
12
|
+
* on a wrapping element does not reach the field. See issue #3343.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const CONTROL = 'input:not([type="hidden"]):not([hidden]), textarea, select, [role="combobox"]'
|
|
16
|
+
|
|
17
|
+
const mount = async (tag: string, attrs = '') => {
|
|
18
|
+
document.body.innerHTML = `<${tag} id="felt" name="felt" label="Etikett" helptext="Hjelpetekst" ${attrs}></${tag}>`
|
|
19
|
+
await customElements.whenDefined(tag)
|
|
20
|
+
const host = document.querySelector(tag) as HTMLElement & { updateComplete: Promise<unknown> }
|
|
21
|
+
await host.updateComplete
|
|
22
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
23
|
+
await host.updateComplete
|
|
24
|
+
return host
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const cases: Array<[string, string]> = [
|
|
28
|
+
['pkt-textinput', ''],
|
|
29
|
+
['pkt-textarea', ''],
|
|
30
|
+
['pkt-select', ''],
|
|
31
|
+
['pkt-datepicker', ''],
|
|
32
|
+
['pkt-fileupload', ''],
|
|
33
|
+
['pkt-combobox', ''],
|
|
34
|
+
['pkt-combobox', 'allow-user-input'],
|
|
35
|
+
['pkt-combobox', 'typeahead'],
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
describe('helptext association', () => {
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
document.body.innerHTML = ''
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test.each(cases)('%s %s describes its control with the helptext', async (tag, attrs) => {
|
|
44
|
+
const host = await mount(tag, attrs)
|
|
45
|
+
|
|
46
|
+
const helptext = host.querySelector('.pkt-inputwrapper__helptext')
|
|
47
|
+
expect(helptext?.id).toBeTruthy()
|
|
48
|
+
|
|
49
|
+
const control = host.querySelector(CONTROL)
|
|
50
|
+
expect(control).not.toBeNull()
|
|
51
|
+
expect(control?.getAttribute('aria-describedby')?.split(' ')).toContain(helptext?.id)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('pkt-timepicker describes both spinbuttons with the helptext', async () => {
|
|
55
|
+
const host = await mount('pkt-timepicker')
|
|
56
|
+
|
|
57
|
+
const helptext = host.querySelector('.pkt-inputwrapper__helptext')
|
|
58
|
+
expect(helptext?.id).toBeTruthy()
|
|
59
|
+
|
|
60
|
+
const spinbuttons = host.querySelectorAll('[role="spinbutton"]')
|
|
61
|
+
expect(spinbuttons).toHaveLength(2)
|
|
62
|
+
spinbuttons.forEach((spinbutton) => {
|
|
63
|
+
expect(spinbutton.getAttribute('aria-describedby')?.split(' ')).toContain(helptext?.id)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('pkt-fileupload renders and links the helptext without a label', async () => {
|
|
68
|
+
document.body.innerHTML = `<pkt-fileupload id="felt" name="felt" helptext="Hjelpetekst"></pkt-fileupload>`
|
|
69
|
+
await customElements.whenDefined('pkt-fileupload')
|
|
70
|
+
const host = document.querySelector('pkt-fileupload') as HTMLElement & {
|
|
71
|
+
updateComplete: Promise<unknown>
|
|
72
|
+
}
|
|
73
|
+
await host.updateComplete
|
|
74
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
75
|
+
await host.updateComplete
|
|
76
|
+
|
|
77
|
+
const helptext = host.querySelector('.pkt-inputwrapper__helptext')
|
|
78
|
+
expect(helptext?.textContent).toContain('Hjelpetekst')
|
|
79
|
+
|
|
80
|
+
const input = host.querySelector('input[type="file"]')
|
|
81
|
+
expect(input?.getAttribute('aria-describedby')?.split(' ')).toContain(helptext?.id)
|
|
82
|
+
expect(input?.getAttribute('aria-label')).toBe('Velg fil')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('no label carries the description', async () => {
|
|
86
|
+
for (const [tag, attrs] of cases) {
|
|
87
|
+
const host = await mount(tag, attrs)
|
|
88
|
+
const labels = host.querySelectorAll('label[aria-describedby], legend[aria-describedby]')
|
|
89
|
+
expect(labels).toHaveLength(0)
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('nothing points at an element that is not rendered', async () => {
|
|
94
|
+
for (const [tag, attrs] of [...cases, ['pkt-timepicker', ''] as [string, string]]) {
|
|
95
|
+
const host = await mount(tag, attrs)
|
|
96
|
+
host.querySelectorAll('[aria-describedby]').forEach((el) => {
|
|
97
|
+
el.getAttribute('aria-describedby')
|
|
98
|
+
?.split(' ')
|
|
99
|
+
.filter(Boolean)
|
|
100
|
+
.forEach((id) => {
|
|
101
|
+
expect(`${tag} ${attrs} -> ${document.getElementById(id) ? 'finnes' : 'mangler'}`).toBe(
|
|
102
|
+
`${tag} ${attrs} -> finnes`,
|
|
103
|
+
)
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
})
|
|
@@ -13,6 +13,7 @@ import { stepTime } from 'shared-utils/timepicker/stepper'
|
|
|
13
13
|
import '@/components/icon'
|
|
14
14
|
import '@/components/input-wrapper'
|
|
15
15
|
import { TPktInputSize } from 'shared-types/size'
|
|
16
|
+
import { describedByIds } from 'shared-utils/forms/described-by'
|
|
16
17
|
|
|
17
18
|
type Props = ElementProps<PktTimepicker, 'value' | 'hidePicker' | 'stepArrows'> &
|
|
18
19
|
IPktStringsProps<'timepicker'>
|
|
@@ -145,6 +146,14 @@ export class PktTimepicker extends PktInputElement<Props> {
|
|
|
145
146
|
private _minutesFirstDigit: number = -1
|
|
146
147
|
private _hasFocus: boolean = false
|
|
147
148
|
|
|
149
|
+
private _describedBy(): string | undefined {
|
|
150
|
+
return describedByIds({
|
|
151
|
+
id: `${this.id}-hours`,
|
|
152
|
+
hasHelptext: !!this.helptext,
|
|
153
|
+
ariaDescribedby: this.ariaDescribedby,
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
|
|
148
157
|
private _setAriaInvalid(invalid: boolean): void {
|
|
149
158
|
if (!this.touched && invalid) return
|
|
150
159
|
const hours = this.hoursInputRef.value
|
|
@@ -660,6 +669,7 @@ export class PktTimepicker extends PktInputElement<Props> {
|
|
|
660
669
|
role="spinbutton"
|
|
661
670
|
aria-invalid=${this.hasError ? 'true' : nothing}
|
|
662
671
|
aria-errormessage=${this.hasError ? `${this.id}-hours-error` : nothing}
|
|
672
|
+
aria-describedby=${ifDefined(this._describedBy())}
|
|
663
673
|
aria-valuemin="0"
|
|
664
674
|
aria-valuemax="23"
|
|
665
675
|
aria-valuenow=${this._hours !== '' ? this._hours : nothing}
|
|
@@ -692,6 +702,7 @@ export class PktTimepicker extends PktInputElement<Props> {
|
|
|
692
702
|
role="spinbutton"
|
|
693
703
|
aria-invalid=${this.hasError ? 'true' : nothing}
|
|
694
704
|
aria-errormessage=${this.hasError ? `${this.id}-hours-error` : nothing}
|
|
705
|
+
aria-describedby=${ifDefined(this._describedBy())}
|
|
695
706
|
aria-valuemin="0"
|
|
696
707
|
aria-valuemax="59"
|
|
697
708
|
aria-valuenow=${this._minutes !== '' ? this._minutes : nothing}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
const e=require("./element-D_mCyFeX.cjs"),t=require("./class-map-DupQbnhE.cjs"),n=require("./if-defined-BbUZeoaQ.cjs"),r=require("./format-B8meU8Tm.cjs"),i=require("./element-with-slot-C66Jck5e.cjs");require("./icon-BzxBkRyE.cjs");const a=require("./ref-AuNEkS5a.cjs");require("./tag-CGlxtBOH.cjs");const o=require("./repeat-B3ksuY2F.cjs"),s=require("./listbox-kV4OO1Qa.cjs"),c=require("./input-element-PN5nWd1A.cjs"),l=require("./pkt-options-controller-DXAAVcBJ.cjs");require("./input-wrapper-D64Qn-QH.cjs");var u=(e,t,n)=>{switch(e){case`,`:return n?`addValue`:null;case`Enter`:return`addValue`;case`Tab`:case`ArrowDown`:return t?null:`focusListbox`;case`Escape`:return`closeOptions`;default:return null}},d=(e,t,n,r,i)=>{if(!e)return{action:`none`,value:null};let a=s.i(n,e);return!t.includes(e)&&!a?r?{action:`addUserValue`,value:e}:i?{action:`none`,value:null}:{action:`removeValue`,value:t[0]}:a&&!t.includes(a.value)?{action:`selectOption`,value:a.value}:{action:`none`,value:null}},f=(e,t,n,r,i)=>e.trim().toLowerCase()?{...s.c(e,t,n,r),shouldRemoveValue:!1,shouldResetInput:!1}:{addValueText:null,userInfoMessage:``,shouldRemoveValue:!i&&!!t[0],shouldResetInput:!0},p=(e,t,n)=>{let r=s.i(t,e);return n===`label`&&r?.label?r.label:e},m={markOptionSelected(e,t){if(t){for(let n of e)if(n.value===t){n.selected=!0;break}}},markOptionDeselected(e,t){if(t){for(let n of e)if(n.value===t){n.selected=!1;break}}},markAllSelected(e){for(let t of e)t.selected=!0},markAllDeselected(e){for(let t of e)t.selected=!1},removeUserAddedOptions(e){return e.filter(e=>!e.userAdded)}},h={parseOptionsFromSlot(e){let t=[];return e.forEach(e=>{if(!e.textContent&&!e.getAttribute(`value`))return;let n={value:e.getAttribute(`value`)||e.textContent||``,label:e.textContent||e.getAttribute(`value`)||``};e.getAttribute(`data-prefix`)&&(n.prefix=e.getAttribute(`data-prefix`)||void 0),e.getAttribute(`tagskincolor`)&&(n.tagSkinColor=e.getAttribute(`tagskincolor`)),e.getAttribute(`description`)&&(n.description=e.getAttribute(`description`)||void 0),n.fulltext=s.r(n),t.push(n)}),t}},g={cloneOptions(e){return Array.isArray(e)?e.map(e=>({...e})):[]},syncOptionsWithValues(e,t){let n=[...t];return e.forEach(e=>{e.value&&!e.label&&(e.label=e.value),e.selected&&!n.includes(e.value)&&n.push(e.value),e.fulltext=s.r(e),e.selected=e.selected||n.includes(e.value)}),{options:e,newValues:n}},mergeWithUserAdded(e,t,n){return[...t.filter(e=>e?.userAdded&&n.includes(e.value)).filter(t=>!(Array.isArray(e)?e:[]).some(e=>e.value===t.value)),...e]}},_={name:`pkt-combobox`,react:`PktCombobox`,"css-class":`pkt-combobox`,isElement:!0,isPureReact:!0,props:{name:{type:`string`,name:`Navn`,description:`Navn som brukes i skjema ved innsending`,category:`tech`},form:{name:`Skjema`,description:`ID-en til skjemaet feltet hører til, når feltet ligger utenfor skjemaet`,type:`string`,required:!1,category:`tech`},id:{type:`string`,name:`ID`,description:`Unik ID for feltet`,category:`tech`},label:{type:`string`,name:`Etikett/label`,description:`Tekst som vises over feltet`,category:`contents`},placeholder:{name:`Hint`,description:`Spesifiserer en kort hint som beskriver forventet verdi av feltet.`,type:`string`,category:`contents`,required:!1},multiple:{type:`boolean`,name:`Flervalg`,default:!1,description:`Mulighet for å velge flere valg`,category:`functionality`},tagPlacement:{attribute:`tag-placement`,type:[`inside`,`outside`],name:`Plassering av tags i flervalg`,description:`Plassering av valgte verdier i feltet ved flervalg`,category:`functionality`,showIf:{multiple:!0}},maxlength:{type:`number`,name:`Maks antall i flervalg`,description:`Maks antall valg dersom flervalg er aktivert`,category:`functionality`,showIf:{multiple:!0}},typeahead:{type:`boolean`,name:`Typeahead`,default:!1,description:`Mulighet for automatisk utfylling av feltet fra listen over valg`,category:`functionality`},includeSearch:{attribute:`include-search`,type:`boolean`,name:`Inkluder søk`,description:`Mulighet for å søke etter valg inni dropdown`,category:`functionality`},allowUserInput:{attribute:`allow-user-input`,type:`boolean`,name:`Brukervalgte verdier`,description:`Mulighet for å skrive inn egne verdier`,category:`functionality`},searchPlaceholder:{attribute:`search-placeholder`,type:`string`,name:`Søke-plassholder`,description:`Plassholdertekst for søkefeltet i dropdown`,category:`contents`,showIf:{includeSearch:!0}},displayValueAs:{attribute:`display-value-as`,type:[`label`,`value`,`prefixAndValue`],name:`Visning av valgt verdi`,description:`Hvordan valgt verdi vises i feltet`,default:`label`,category:`ui`},inputSize:{name:`Størrelse`,description:`Visuell størrelse via input-wrapper. small: kompakt wrapper og felt (42px). xsmall: samme wrapper som small, felt 36px.`,attribute:`input-size`,type:[`small`,`medium`,`xsmall`],default:`medium`,category:`ui`},value:{name:`Verdi`,type:`string`,description:`Valgt verdi. Streng ved enkelt valg, array av strenger ved flervalg.`,category:`tech`},helptext:{type:`string`,name:`Hjelpetekst`,description:`Hjelpetekst som vises over feltet`,category:`contents`},helptextDropdown:{attribute:`helptextdropdown`,type:`string`,name:`Utvidet hjelpetekst`,description:`Hjelpetekst som vises i en lukket boks man kan åpne`,category:`contents`},helptextDropdownButton:{attribute:`helptextdropdownbutton`,type:`string`,name:`Knappetekst for hjelpetekst`,description:`Tekst som vises på knappen for å åpne/lukke utvidet hjelpetekst`,category:`contents`,default:`Les mer`},disabled:{type:`boolean`,name:`Deaktivert`,description:`Feltet er deaktivert`,category:`tech`},hasError:{attribute:`haserror`,type:`boolean`,name:`Feil`,description:`Feltet har en feil`,category:`ui`},errorMessage:{attribute:`errormessage`,type:`string`,name:`Feilmelding`,description:`Tekst som vises under feltet ved feil`,category:`contents`},required:{type:`boolean`,name:`Påkrevd`,description:`Feltet må fylles ut`,category:`tech`},requiredTag:{attribute:`requiredtag`,type:`boolean`,name:`Påkrevd-merking`,description:`Viser en merking som indikerer at feltet er påkrevd`,category:`ui`},requiredText:{attribute:`requiredtext`,type:`string`,name:`Påkrevd-tekst`,description:`Tekst som vises i påkrevd-merkingen`,category:`contents`},optionalTag:{attribute:`optionaltag`,type:`boolean`,name:`Valgfritt-merking`,description:`Viser en merking som indikerer at feltet er valgfritt`,category:`ui`},optionalText:{attribute:`optionaltext`,type:`string`,name:`Valgfritt-tekst`,description:`Tekst som vises i valgfritt-merkingen`,category:`contents`},tagText:{attribute:`tagtext`,type:`string`,name:`Tag-tekst`,description:`Tekst som vises i en tag ved siden av label`,category:`ui`},fullwidth:{type:`boolean`,name:`Full bredde`,description:`Skal feltet ta opp hele bredden?`,category:`ui`},defaultOptions:{attribute:`default-options`,name:`Initielle valg (default options)`,description:`Liste over valg som kan velges, om options sendes inn som array med objekter (denne vil ikke modifiseres ved endring innad i komponenten)`,type:`array`,default:[],previewDefault:[{value:`bfr`,label:`Frogner`},{value:`bgo`,label:`Gamle Oslo`},{value:`bgr`,label:`Grorud`},{value:`bxx`,label:`Andre bydeler`}],items:{type:`object`,properties:{value:{type:`string`,description:`Verdi som sendes ved valg`},label:{type:`string`,description:`Tekst som vises for valget`},prefix:{type:`string`,description:`Tekst som vises før valget`},description:{type:`string`,description:`Beskrivelse av valget`},disabled:{type:`boolean`,description:`Valget er deaktivert`},selected:{type:`boolean`,description:`Valget er valgt`},tagSkinColor:{type:[`blue`,`blue-dark`,`blue-light`,`green`,`red`,`yellow`,`beige`,`gray`,`grey`],description:`Farge på tag`}},required:[`value`]},category:`contents`},options:{name:`Valg`,type:`array`,description:`Liste over valg som kan velges, om options sendes inn som array med objekter`,default:[],items:{type:`object`,properties:{value:{type:`string`,description:`Verdi som sendes ved valg`},label:{type:`string`,description:`Tekst som vises for valget`},prefix:{type:`string`,description:`Tekst som vises før valget`},description:{type:`string`,description:`Beskrivelse av valget`},disabled:{type:`boolean`,description:`Valget er deaktivert`},selected:{type:`boolean`,description:`Valget er valgt`},tagSkinColor:{type:[`blue`,`blue-dark`,`blue-light`,`green`,`red`,`yellow`,`beige`,`gray`,`grey`],description:`Farge på tag`}},required:[`value`]},category:`contents`},inline:{name:`Inline`,type:`boolean`,required:!1,default:!1,description:`Angir om feltet skal flyte med teksten`,category:`ui`},useWrapper:{attribute:`usewrapper`,name:`Bruk wrapper`,type:`boolean`,required:!1,displayAsFalse:!0,default:!0,description:`Indikerer om skjemaelementet skal bruke en wrapper`,category:`ui`},hasFieldset:{attribute:`hasfieldset`,name:`Bruk fieldset`,type:`boolean`,required:!1,default:null,description:`Bruk fieldset og legend i stedet for label. Utledes automatisk når feltet ikke har en input.`,category:`ui`},counter:{name:`Teller`,type:`boolean`,required:!1,default:null,description:`Viser teller under feltet. Slås på av seg selv når det finnes en grense å telle mot; sett til false for å skru den av.`,category:`ui`},defaultValue:{attribute:`defaultvalue`,type:`string | string[]`,name:`Standardverdi`,description:`Verdien feltet får ved oppstart og ved nullstilling av skjemaet`,category:`functionality`}},events:{change:{type:`Event`,description:`Returnerer valgt verdi som streng. Ved flervalg returneres kommaseparerte verdier.`},"value-change":{type:`CustomEvent`,description:`Returnerer valgt verdi. Ved enkeltvalg en streng, ved flervalg en <code>string[]</code>.`},search:{type:`CustomEvent`,description:`Returnerer søketeksten som streng i <code>event.detail</code> når brukeren skriver i søkefeltet`},toggleHelpText:{type:`CustomEvent`,description:`Returnerer <code>event.detail { isOpen: true }</code> eller <code>event.detail { isOpen: false }</code> når hjelpeteksten åpnes eller lukkes`}}},v=class extends c.t{constructor(){super(),this.value=``,this.options=[],this.defaultOptions=[],this.allowUserInput=!1,this.typeahead=!1,this.includeSearch=!1,this.searchPlaceholder=null,this.multiple=!1,this.maxlength=null,this.displayValueAs=_.props.displayValueAs.default,this.tagPlacement=null,this.isOpen=!1,this._options=[],this._value=[],this._isOptionsOpen=!1,this._userInfoMessage=``,this._messageValue=null,this._addValueText=null,this._maxIsReached=!1,this._search=``,this._inputFocus=!1,this._skipInputTab=!1,this._optionsFromSlot=!1,this._lastSlotGeneration=0,this._suppressNextOpen=!1,this.inputRef=a.t(),this.triggerRef=a.t(),this.listboxRef=a.t(),this._pendingDispatchFrom=null,this.optionsController=new l.t(this)}get _hasTextInput(){return this.typeahead||this.allowUserInput}get _selectionDescription(){if(!(!this.multiple||this._value.length===0))return`${this._value.length} valgt`}focusTrigger(){this._hasTextInput?this.inputRef.value?.focus():this.triggerRef.value?.focus()}focusAfterCommit(){this._skipInputTab=!0;let e=this.inputRef.value;e&&e.type!==`hidden`&&e.setAttribute(`tabindex`,`-1`),this.triggerRef.value?.focus()}restoreInputTab(){this._skipInputTab=!1}parseValue(){return this.parseToValues(this.value)}parseToValues(e){return Array.isArray(e)?this.multiple?e:e.length>0?[e[0]]:[]:e&&this.multiple?e.split(`,`):e?[e]:[]}updateMaxReached(){this._maxIsReached=s.l(this._value.length,this.maxlength)}syncPublicValue(){let e=this.multiple?this._value.join(`,`):this._value[0]||``;e!==(Array.isArray(this.value)?this.value.join(`,`):String(this.value||``))&&(this.value=e)}dispatchValueChange(e){let t=this._value;if(e?.join(`,`)!==t.join(`,`)){let e=this.multiple?[...t]:t[0]||``;this.onChange(e)}else t.length===0&&e&&e.length>0&&this.clearInputValue()}onChange(e){this.touched=!0,super.onChange(e)}valueChanged(){}};e.n([e.u({type:String,reflect:!0})],v.prototype,`value`,void 0),e.n([e.u({type:Array})],v.prototype,`options`,void 0),e.n([e.u({type:Array,attribute:`default-options`})],v.prototype,`defaultOptions`,void 0),e.n([e.u({type:Boolean,attribute:`allow-user-input`})],v.prototype,`allowUserInput`,void 0),e.n([e.u({type:Boolean})],v.prototype,`typeahead`,void 0),e.n([e.u({type:Boolean,attribute:`include-search`})],v.prototype,`includeSearch`,void 0),e.n([e.u({type:String,attribute:`search-placeholder`})],v.prototype,`searchPlaceholder`,void 0),e.n([e.u({type:Boolean})],v.prototype,`multiple`,void 0),e.n([e.u({type:Number})],v.prototype,`maxlength`,void 0),e.n([e.u({type:String,attribute:`display-value-as`})],v.prototype,`displayValueAs`,void 0),e.n([e.u({type:String,attribute:`tag-placement`})],v.prototype,`tagPlacement`,void 0),e.n([e.u({type:Boolean,attribute:`open`})],v.prototype,`isOpen`,void 0),e.n([e.l()],v.prototype,`_options`,void 0),e.n([e.l()],v.prototype,`_value`,void 0),e.n([e.l()],v.prototype,`_isOptionsOpen`,void 0),e.n([e.l()],v.prototype,`_userInfoMessage`,void 0),e.n([e.l()],v.prototype,`_messageValue`,void 0),e.n([e.l()],v.prototype,`_addValueText`,void 0),e.n([e.l()],v.prototype,`_maxIsReached`,void 0),e.n([e.l()],v.prototype,`_search`,void 0),e.n([e.l()],v.prototype,`_inputFocus`,void 0),e.n([e.l()],v.prototype,`_skipInputTab`,void 0);var y=class extends v{toggleValue(e){if(this.disabled)return;this.touched=!0,this._userInfoMessage=``,this._addValueText=null;let t=s.i(this.options,e)?.value||null,n=this._value.includes(e||t||``),r=!!t,i=this._options.find(t=>t.value===e)?.disabled||!1,a=!e?.trim(),o=!this.multiple,c=this.multiple,l=s.l(this._value.length,this.maxlength),u=!1,d=!0,f=``,m=null,h=``;i||(!r&&this.allowUserInput&&!a?(this.addNewUserValue(e),f=`valueAdded`,u=c):!r&&!this.allowUserInput?(o&&this._value[0]&&this.removeValue(this._value[0]),d=!1,u=!0,f=`noResults`):n?(this.removeValue(t),u=!0,o&&this._hasTextInput&&this.inputRef.value&&this.inputRef.value.type!==`hidden`&&(this.inputRef.value.value=``)):a&&o?(this.removeAllSelected(),u=!0):o?(this._value[0]&&this.removeSelected(this._value[0]),this.setSelected(t),u=!1,f=`valueSelected`,m=this._hasTextInput?p(t||``,this.options,this.displayValueAs):s.s(s.i(this.options,t),this.displayValueAs)):c&&!l?(this.setSelected(t),u=!0):c&&l?(f=`maxSelected`,d=!1,h=e):(o&&this.removeAllSelected(),f=`noValidValue`,d=!1,u=!0,h=e),this._isOptionsOpen=u,u||window.setTimeout(()=>{this.focusAfterCommit()},0),this._search=h||``,this.resetComboboxInput(d),this._userInfoMessage=f,this._messageValue=m,c&&this.updateMaxReached())}setSelected(e){if(!this._value.includes(e)){if(this.multiple&&s.l(this._value.length,this.maxlength)){this._userInfoMessage=`maxSelected`;return}!this.multiple&&this.removeAllSelected(),this._value=e?[...this._value,e]:this._value,m.markOptionSelected(this._options,e),this.resetComboboxInput(!0)}}removeSelected(e){if(!e)return;this._value=this._value.filter(t=>t!==e);let t=s.i(this.options,e);t&&(m.markOptionDeselected(this.options,e),t.userAdded?(this._options=[...this._options.filter(t=>t.value!==e)],this.options=[...this.options.filter(t=>t.value!==e)]):this._options.some(t=>t.value===e)||(this._options=[...this._options,t]))}addAllOptions(){if(this.multiple){if(this.maxlength&&this._options.length>this.maxlength){this._userInfoMessage=`tooManySelected`;return}this._value=this._options.map(e=>e.value),m.markAllSelected(this._options),this.requestUpdate()}}removeAllSelected(){this._value=[],m.markAllDeselected(this._options),this._options=m.removeUserAddedOptions(this._options),this.requestUpdate()}addValue(){let e=this.inputRef.value?.value.trim()||``;if(this._search=e,e&&this._value.includes(e)){this.resetComboboxInput(!0),this._userInfoMessage=`alreadySelected`;return}this.toggleValue(e)}removeValue(e){this._value=this.multiple?this._value.filter(t=>t!==e):[],this.removeSelected(e)}addNewUserValue(e){if(!e||e.trim()===``)return;if(!this.multiple)this._value[0]&&this.removeSelected(this._value[0]),this._value=[e];else if(!s.i(this.options,e)){if(s.l(this._value.length,this.maxlength))return;this._value=[...this._value,e]}let t={value:e,label:e,userAdded:!0,selected:!0};this.options=[t,...this.options],this._options=[t,...this._options],this.resetComboboxInput(!0),this.multiple||(this._isOptionsOpen=!1,window.setTimeout(()=>{this.focusAfterCommit()},0)),this.requestUpdate()}refreshOptionsFromValue(){let e=g.cloneOptions(this.options);e.forEach(e=>e.selected=this._value.includes(e.value)),this._options=g.syncOptionsWithValues(e,this._value).options}resetComboboxInput(e=!0){this._addValueText=null,this.inputRef.value&&this.inputRef.value.type!==`hidden`&&e&&(this._search=``,this.multiple?this.inputRef.value.value=``:(this.inputRef.value.value=this._value[0]?p(this._value[0],this.options,this.displayValueAs):``,this._userInfoMessage=``)),this.refreshOptionsFromValue()}removeLastValue(e){if(this._value.length===0)return;e.preventDefault();let t=this._value[this._value.length-1];t&&this.removeSelected(t),this.updateMaxReached()}},b=class extends y{handleInput(e){if(e.stopPropagation(),e.stopImmediatePropagation(),this.disabled)return;this.touched=!0;let t=e.target;if(this._search=t.value,this.checkForMatches(),this.typeahead){if(this._search){let{filtered:n,suggestion:r}=s.o(this.options,this._search);this._options=n,e.inputType!==`deleteContentBackward`&&r?.label&&this.inputRef.value&&this.inputRef.value.type!==`hidden`&&(t.value=r.label,window.setTimeout(()=>t.setSelectionRange(this._search.length,t.value.length),0),t.selectionDirection=`backward`)}else this.refreshOptionsFromValue()}}handleFocus(){if(!this.disabled){if(this._skipInputTab=!1,this._suppressNextOpen){this._suppressNextOpen=!1,this._inputFocus=!0,this.requestUpdate();return}!this.multiple&&this._value[0]&&this.inputRef.value&&this.inputRef.value.type!==`hidden`&&(this.inputRef.value.value=p(this._value[0],this.options,this.displayValueAs)),this._inputFocus=!0,this._search=``,this.refreshOptionsFromValue(),this._isOptionsOpen=!0,this.onFocus(),this.requestUpdate()}}handleCloseOptions(){this._isOptionsOpen=!1,this._hasTextInput&&(this._suppressNextOpen=!0),this.focusTrigger()}handleFocusOut(e){if(this.disabled||!this._isOptionsOpen)return;let t=e.relatedTarget;t?.closest(`pkt-combobox`)?.id===this.id||e.target?.classList?.contains(`pkt-combobox__value`)||t===this.inputRef.value||t===this.triggerRef.value||this.closeAndProcessInput()}closeAndProcessInput(){if(this._inputFocus=!1,this._addValueText=null,this._userInfoMessage=``,this._search=``,this.inputRef.value&&this.inputRef.value.type!==`hidden`){let e=this.inputRef.value.value;if(!this.multiple){if(!e)this._value[0]&&this.removeSelected(this._value[0]);else{let t=s.i(this.options,e);t&&t.value!==this._value[0]?(this._value[0]&&this.removeSelected(this._value[0]),this.setSelected(t.value)):!t&&this.allowUserInput&&(this._value[0]&&this.removeSelected(this._value[0]),this.addNewUserValue(e))}}else if(e!==``){let{action:t,value:n}=d(e,this._value,this.options,this.allowUserInput,this.multiple);switch(t){case`addUserValue`:this.addNewUserValue(n);break;case`selectOption`:this.setSelected(n);break;case`removeValue`:this.removeValue(n)}}!this.multiple&&this._value[0]?this.inputRef.value.value=p(this._value[0],this.options,this.displayValueAs):this.inputRef.value.value=``}this._isOptionsOpen=!1,this.onBlur()}handleBlur(){this._inputFocus=!1,this.onBlur()}handleInputClick(e){if(this.disabled){e.preventDefault(),e.stopImmediatePropagation();return}this._hasTextInput?(this.inputRef.value?.focus(),this.requestUpdate()):(e.stopImmediatePropagation(),e.preventDefault(),this._isOptionsOpen=!this._isOptionsOpen,this._isOptionsOpen&&this.listboxRef.value?.focusFirstOrSelectedOption())}handlePlaceholderClick(e){this.disabled||(e.stopPropagation(),this._hasTextInput&&this.inputRef.value?(this.inputRef.value.focus(),this._inputFocus=!0,this.requestUpdate()):(this._isOptionsOpen=!this._isOptionsOpen,this.requestUpdate()))}handleSelectOnlyKeydown(e){if(!this.disabled)switch(e.key){case`Enter`:case` `:case`ArrowDown`:case`ArrowUp`:e.preventDefault(),this._isOptionsOpen?this._isOptionsOpen=!1:(this._isOptionsOpen=!0,this.listboxRef.value?.focusFirstOrSelectedOption());break;case`Escape`:this._isOptionsOpen&&=(e.preventDefault(),!1);break;case`Home`:case`End`:e.preventDefault(),this._isOptionsOpen||=!0,this.listboxRef.value?.focusFirstOrSelectedOption();break;case`ArrowLeft`:this.multiple&&this._value.length>0&&(e.preventDefault(),this.focusTag(this._value.length-1));break;case`Backspace`:case`Delete`:this.multiple&&this._value.length>0&&(e.preventDefault(),this.removeSelected(this._value[this._value.length-1]))}}handleOptionToggled(e){this.toggleValue(e.detail)}handleSearch(e){e.stopPropagation(),this._search=e.detail.toLowerCase(),this.checkForMatches()}handleInputKeydown(e){if(e.key===`Backspace`){let t=!this.inputRef.value?.value;!this._search&&t&&this.multiple&&this._value.length>0&&this.removeLastValue(e);return}if(e.key===`ArrowLeft`&&this.multiple&&this._value.length>0){let t=this.inputRef.value;if(t&&t.selectionStart===0&&!t.value){e.preventDefault(),this.focusTag(this._value.length-1);return}}let t=u(e.key,e.shiftKey,this.multiple);if(t&&!(e.key===`Tab`&&!this._isOptionsOpen)){if(t===`focusListbox`&&e.key===`Tab`&&!this.listboxRef.value?.querySelector(`[role="option"]:not([data-disabled]), [data-type="new-option"]`)){this.closeAndProcessInput();return}switch(e.preventDefault(),t){case`addValue`:this.addValue();break;case`focusListbox`:this.listboxRef.value?.focusFirstOrSelectedOption();break;case`closeOptions`:this._isOptionsOpen=!1}}}handleTagRemove(e){this.removeSelected(e),this._hasTextInput&&this.inputRef.value&&(this._inputFocus=!0,this.inputRef.value.focus(),this.requestUpdate())}getInsideTags(){return Array.from(this.querySelectorAll(`.pkt-combobox__input .pkt-combobox__tag-list pkt-tag`))}focusTag(e){let t=this.getInsideTags();t.forEach((t,n)=>{t.buttonTabindex=n===e?0:-1}),(t[e]?.querySelector(`button`))?.focus()}resetTagTabindices(){this.getInsideTags().forEach(e=>{e.buttonTabindex=-1})}handleTagKeydown(e,t){e.stopPropagation();let n=()=>{this.resetTagTabindices(),this._hasTextInput&&this.inputRef.value?this.inputRef.value.focus():this.triggerRef.value?.focus()};switch(e.key){case`ArrowLeft`:e.preventDefault(),t>0&&this.focusTag(t-1);break;case`ArrowRight`:e.preventDefault(),t<this._value.length-1?this.focusTag(t+1):n();break;case`Backspace`:case`Delete`:e.preventDefault();{let e=this._value[t],r=t>=this._value.length-1?t-1:t;this.removeSelected(e),r>=0?(this.requestUpdate(),this.updateComplete.then(()=>this.focusTag(r))):n()}break;case`Tab`:this.resetTagTabindices();break;case`Escape`:e.preventDefault(),n()}}checkForMatches(){let e=f(this.inputRef.value?.value||this._search||``,this._value,this.options,this.allowUserInput,this.multiple);if(e.shouldRemoveValue&&this.removeValue(this._value[0]),e.shouldResetInput){this.resetComboboxInput(!1);return}this._addValueText=e.addValueText,this._userInfoMessage=e.userInfoMessage}},x=class extends b{constructor(...e){super(...e),this.handleBodyClick=e=>{this._isOptionsOpen&&!this.contains(e.target)&&this.closeAndProcessInput()}}connectedCallback(){if(super.connectedCallback(),document?.body.addEventListener(`click`,this.handleBodyClick),this._options=[],this.defaultOptions&&this.defaultOptions.length){let e=this.options?.filter(e=>e.userAdded)||[];this.options=[...e,...JSON.parse(JSON.stringify(this.defaultOptions))],this._options=g.cloneOptions(this.options)}if(this.optionsController?.nodes&&this.optionsController.nodes.length){let e=h.parseOptionsFromSlot(this.optionsController.nodes);e.length&&(this.options=[...e],this._options=[...e],this._optionsFromSlot=!0,this._lastSlotGeneration=this.optionsController.generation)}}disconnectedCallback(){super.disconnectedCallback(),document?.body.removeEventListener(`click`,this.handleBodyClick)}firstUpdated(e){this.defaultValue!==null&&!this.value&&(this.value=this.defaultValue),super.firstUpdated(e)}willUpdate(e){if(this._optionsFromSlot&&this.optionsController){let e=this.optionsController.generation;if(e!==this._lastSlotGeneration){this._lastSlotGeneration=e;let t=h.parseOptionsFromSlot(this.optionsController.nodes),n=this._options.filter(e=>e.userAdded);this.options=[...n,...t]}}if(super.willUpdate(e),e.has(`isOpen`)&&(this._isOptionsOpen=this.isOpen),e.has(`defaultOptions`)&&this.defaultOptions.length){let e=(Array.isArray(this.options)?this.options:[]).filter(e=>e.userAdded)||[];this.options=[...e,...JSON.parse(JSON.stringify(this.defaultOptions))],this._options=g.cloneOptions(this.options)}let t=e.has(`value`),n=e.has(`_value`);if(t){let e=[...this._value],t=this.parseValue();t.join(`,`)!==this._value.join(`,`)&&(this._value=t,this._options.forEach(e=>e.selected=t.includes(e.value)),this._options=[...this._options]),this._pendingDispatchFrom??=e}else n&&(this._pendingDispatchFrom??=e.get(`_value`)??[]);if(e.has(`defaultValue`)&&this.defaultValue!=null&&!this._value.length){let e=this.parseToValues(this.defaultValue);e.length&&(this._pendingDispatchFrom??=[...this._value],this._value=e,this._options.forEach(t=>t.selected=e.includes(t.value)),this._options=[...this._options])}if(e.has(`options`)){let t=e.get(`options`)||this._options||[],n=g.mergeWithUserAdded(g.cloneOptions(this.options),t,this._value);this._options=n,n.length>this.options.length&&(this.options=n);let r=g.syncOptionsWithValues(this._options,this._value);this._options=r.options,r.newValues.length>this._value.length&&(this._pendingDispatchFrom??=[...this._value],this._value=r.newValues)}(t||n||e.has(`options`)||e.has(`defaultValue`))&&this.updateMaxReached(),this._pendingDispatchFrom&&this.syncPublicValue()}updated(e){if(this._pendingDispatchFrom){let e=this._pendingDispatchFrom;this._pendingDispatchFrom=null,this.dispatchValueChange(e)}if(e.has(`_search`)&&this.dispatchEvent(new CustomEvent(`search`,{detail:this._search,bubbles:!1})),!this._isOptionsOpen&&this._hasTextInput&&this.inputRef.value&&this.inputRef.value.type!==`hidden`){let e=!this.multiple&&this._value[0]?p(this._value[0],this.options,this.displayValueAs):``;this.inputRef.value.value!==e&&(this.inputRef.value.value=e)}this.classList.add(`pkt-combobox-component`),this.classList.toggle(`pkt-combobox-component--fullwidth`,!!this.fullwidth),super.updated(e)}formResetCallback(){this.touched=!1;let e=this.defaultValue||(this.multiple,``);this.value=e,this._value=this.parseValue(),this._options=this._options.filter(e=>!e.userAdded).map(e=>({...e,selected:this._value.includes(e.value)})),this.options=this.options.filter(e=>!e.userAdded).map(e=>({...e,selected:this._value.includes(e.value)})),this._search=``,this._isOptionsOpen=!1,this._userInfoMessage=``,this._addValueText=null,this._inputFocus=!1,this.updateMaxReached(),this.inputRef.value&&this.inputRef.value.type!==`hidden`&&(this.inputRef.value.value=``),this.internals.setFormValue(``),this.internals.ariaInvalid=`false`,this.requestUpdate()}attributeChangedCallback(e,t,n){if(e===`options`){this._options=g.cloneOptions(this.options);let e=g.syncOptionsWithValues(this._options,this._value);this._options=e.options,e.newValues.length>this._value.length&&(this._value=e.newValues),this._search=``}super.attributeChangedCallback(e,t,n)}render(){return e._`
|
|
2
|
-
<pkt-input-wrapper
|
|
3
|
-
.strings=${this.strings}
|
|
4
|
-
.size=${this.inputSize}
|
|
5
|
-
.label=${this.label}
|
|
6
|
-
.helptext=${this.helptext}
|
|
7
|
-
.helptextDropdown=${n.t(this.helptextDropdown)}
|
|
8
|
-
.helptextDropdownButton=${n.t(this.helptextDropdownButton)}
|
|
9
|
-
?fullwidth=${this.fullwidth}
|
|
10
|
-
?counter=${this.effectiveCounter(!!this.multiple&&this.maxlength!=null)}
|
|
11
|
-
.counterCurrent=${this._value.length}
|
|
12
|
-
.counterMaxLength=${this.maxlength??0}
|
|
13
|
-
?hasError=${this.hasError}
|
|
14
|
-
?inline=${this.inline}
|
|
15
|
-
?disabled=${this.disabled}
|
|
16
|
-
.errorMessage=${this.errorMessage}
|
|
17
|
-
?optionalTag=${this.optionalTag}
|
|
18
|
-
.optionalText=${this.optionalText}
|
|
19
|
-
?requiredTag=${this.requiredTag}
|
|
20
|
-
.requiredText=${this.requiredText}
|
|
21
|
-
.tagText=${this.tagText}
|
|
22
|
-
useWrapper=${this.useWrapper}
|
|
23
|
-
.forId=${this._hasTextInput?this.id+`-input`:this.id+`-combobox`}
|
|
24
|
-
?hasFieldset=${this.effectiveHasFieldset(!this._hasTextInput)}
|
|
25
|
-
class="pkt-combobox__wrapper"
|
|
26
|
-
@labelClick=${this.handleInputClick}
|
|
27
|
-
>
|
|
28
|
-
<div class="pkt-contents" slot="helptext">${i.r(this,`helptext`)}</div>
|
|
29
|
-
<div class="pkt-combobox" @focusout=${this.handleFocusOut}>
|
|
30
|
-
<div
|
|
31
|
-
class=${t.t({"pkt-combobox__input":!0,[`pkt-combobox__input--${this.inputSize}`]:!0,"pkt-combobox__input--fullwidth":this.fullwidth,"pkt-combobox__input--open":this._isOptionsOpen,"pkt-combobox__input--error":this.hasError,"pkt-combobox__input--disabled":this.disabled})}
|
|
32
|
-
id=${n.t(this._hasTextInput?void 0:`${this.id}-combobox`)}
|
|
33
|
-
role=${n.t(this._hasTextInput?void 0:`combobox`)}
|
|
34
|
-
aria-expanded=${n.t(this._hasTextInput?void 0:this._isOptionsOpen?`true`:`false`)}
|
|
35
|
-
aria-controls=${n.t(this._hasTextInput?void 0:`${this.id}-listbox`)}
|
|
36
|
-
aria-haspopup=${n.t(this._hasTextInput?void 0:`listbox`)}
|
|
37
|
-
aria-labelledby=${n.t(this._hasTextInput?void 0:`${this.id}-combobox-label`)}
|
|
38
|
-
aria-activedescendant=${n.t(!this._hasTextInput&&this._isOptionsOpen&&this._value[0]&&s.i(this.options,this._value[0])?`${this.id}-listbox-${s.a(this._options,this._value[0])}`:void 0)}
|
|
39
|
-
aria-description=${n.t(this._selectionDescription||void 0)}
|
|
40
|
-
tabindex=${this._hasTextInput||this.disabled?`-1`:`0`}
|
|
41
|
-
@click=${this.handleInputClick}
|
|
42
|
-
@keydown=${this._hasTextInput?e.h:this.handleSelectOnlyKeydown}
|
|
43
|
-
@blur=${this.restoreInputTab}
|
|
44
|
-
${a.n(this.triggerRef)}
|
|
45
|
-
>
|
|
46
|
-
${!this._hasTextInput&&this.placeholder&&(!this._value.length||this.multiple&&this.tagPlacement==`outside`)&&!this._inputFocus?e._`<span class="pkt-combobox__placeholder" @click=${this.handlePlaceholderClick}
|
|
47
|
-
>${this.placeholder}</span
|
|
48
|
-
>`:this.tagPlacement===`outside`?e.h:this.renderSingleOrMultipleValues()}
|
|
49
|
-
${this.renderInputField()}
|
|
50
|
-
<pkt-icon
|
|
51
|
-
class=${t.t({"pkt-combobox__arrow-icon":!0,"pkt-combobox__arrow-icon--open":this._isOptionsOpen})}
|
|
52
|
-
name="chevron-thin-down"
|
|
53
|
-
aria-hidden="true"
|
|
54
|
-
></pkt-icon>
|
|
55
|
-
</div>
|
|
56
|
-
|
|
57
|
-
<pkt-listbox
|
|
58
|
-
id="${this.id}-listbox"
|
|
59
|
-
.options=${this._options}
|
|
60
|
-
.isOpen=${this._isOptionsOpen}
|
|
61
|
-
.searchPlaceholder=${this.searchPlaceholder}
|
|
62
|
-
.label="Liste: ${this.label||``}"
|
|
63
|
-
?disabled=${this.disabled}
|
|
64
|
-
?include-search=${this.includeSearch}
|
|
65
|
-
?is-multi-select=${this.multiple}
|
|
66
|
-
?allow-user-input=${this.allowUserInput&&!this._maxIsReached}
|
|
67
|
-
?max-is-reached=${this._maxIsReached}
|
|
68
|
-
.customUserInput=${n.t(this._addValueText)}
|
|
69
|
-
.userMessage=${this._userInfoMessage?r.t(this.pktStrings.get(`combobox`)[this._userInfoMessage],{value:this._messageValue??``}):``}
|
|
70
|
-
@search=${this.handleSearch}
|
|
71
|
-
@option-toggle=${this.handleOptionToggled}
|
|
72
|
-
@select-all=${this.addAllOptions}
|
|
73
|
-
@close-options=${this.handleCloseOptions}
|
|
74
|
-
@tab-close=${()=>this.closeAndProcessInput()}
|
|
75
|
-
.searchValue=${this._search||null}
|
|
76
|
-
.maxLength=${this.maxlength||0}
|
|
77
|
-
${a.n(this.listboxRef)}
|
|
78
|
-
></pkt-listbox>
|
|
79
|
-
</div>
|
|
80
|
-
|
|
81
|
-
${this.tagPlacement===`outside`&&this.multiple?e._`<div class="pkt-combobox__tags-outside">
|
|
82
|
-
${this.renderSingleOrMultipleValues()}
|
|
83
|
-
</div>`:e.h}
|
|
84
|
-
</pkt-input-wrapper>
|
|
85
|
-
`}renderInputField(){return this.typeahead||this.allowUserInput?e._`
|
|
86
|
-
<div class="pkt-combobox__input-div combobox__input">
|
|
87
|
-
<input
|
|
88
|
-
type="text"
|
|
89
|
-
id="${this.id}-input"
|
|
90
|
-
name=${(this.name||this.id)+`-input`}
|
|
91
|
-
placeholder=${n.t(!this._value.length||this.multiple&&this.tagPlacement===`outside`?this.placeholder:void 0)}
|
|
92
|
-
@input=${this.handleInput}
|
|
93
|
-
@change=${e=>{e.stopPropagation(),e.stopImmediatePropagation()}}
|
|
94
|
-
tabindex=${n.t(this._skipInputTab?`-1`:void 0)}
|
|
95
|
-
@keydown=${this.handleInputKeydown}
|
|
96
|
-
@focus=${this.handleFocus}
|
|
97
|
-
@blur=${this.handleBlur}
|
|
98
|
-
autocomplete="off"
|
|
99
|
-
role="combobox"
|
|
100
|
-
aria-expanded=${this._isOptionsOpen?`true`:`false`}
|
|
101
|
-
aria-label=${n.t(this.label)}
|
|
102
|
-
aria-autocomplete=${this.typeahead?`both`:this.allowUserInput?`list`:`none`}
|
|
103
|
-
aria-controls="${this.id}-listbox"
|
|
104
|
-
aria-activedescendant=${n.t(this._isOptionsOpen&&this._value[0]&&s.i(this.options,this._value[0])?`${this.id}-listbox-${s.a(this._options,this._value[0])}`:void 0)}
|
|
105
|
-
aria-description=${n.t(this._selectionDescription||void 0)}
|
|
106
|
-
${a.n(this.inputRef)}
|
|
107
|
-
/>
|
|
108
|
-
</div>
|
|
109
|
-
`:e._`
|
|
110
|
-
<input
|
|
111
|
-
type="hidden"
|
|
112
|
-
id="${this.id}-input"
|
|
113
|
-
name=${(this.name||this.id)+`-input`}
|
|
114
|
-
.value=${this._value.join(`,`)}
|
|
115
|
-
${a.n(this.inputRef)}
|
|
116
|
-
/>
|
|
117
|
-
`}renderSingleOrMultipleValues(){if(!this.multiple&&this._hasTextInput)return e.h;let t=!this.multiple,n=this.renderValueTag(s.i(this.options,this._value[0])),r=this.tagPlacement===`outside`,i=e._`
|
|
118
|
-
<ul role="list" class="pkt-combobox__tag-list">
|
|
119
|
-
${o.t(this._value,e=>e,(t,n)=>{let i=s.i(this.options,t),a=i?.tagSkinColor;return e._`
|
|
120
|
-
<li
|
|
121
|
-
role="listitem"
|
|
122
|
-
@click=${r?e.h:e=>e.stopPropagation()}
|
|
123
|
-
@mousedown=${r?e.h:e=>e.preventDefault()}
|
|
124
|
-
>
|
|
125
|
-
<pkt-tag
|
|
126
|
-
skin=${a||`blue-dark`}
|
|
127
|
-
?closeTag=${!this.disabled}
|
|
128
|
-
.buttonTabindex=${r?void 0:-1}
|
|
129
|
-
@close=${()=>this.handleTagRemove(t)}
|
|
130
|
-
@keydown=${r?e.h:e=>this.handleTagKeydown(e,n)}
|
|
131
|
-
>
|
|
132
|
-
${this.renderValueTag(i)}
|
|
133
|
-
</pkt-tag>
|
|
134
|
-
</li>
|
|
135
|
-
`})}
|
|
136
|
-
</ul>
|
|
137
|
-
`;return!t&&this._value.length===0?e.h:t?n:i}renderValueTag(t){if(!t)return``;switch(this.displayValueAs){case`prefixAndValue`:return e._`<span class="pkt-combobox__value">${t.prefix||``} ${t.value}</span>`;case`value`:return e._`<span class="pkt-combobox__value">${t.value}</span>`;default:return e._`<span class="pkt-combobox__value">${t.label||t.value}</span>`}}};try{e.d(`pkt-combobox`)(x)}catch{console.warn(`Forsøker å definere <pkt-combobox>, men den er allerede definert`)}var S=x;Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return S}});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require("./element-D_mCyFeX.cjs");var t=t=>t??e.h;Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
|