@oslokommune/punkt-react 20.1.3 → 20.1.5
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 +16 -0
- package/dist/components/combobox/Listbox.js +3 -3
- package/dist/punkt-react.cjs +1 -1
- package/package.json +2 -2
- package/src/components/combobox/Combobox.core.test.tsx +13 -0
- package/src/components/combobox/Combobox.interaction.test.tsx +35 -0
- package/src/components/combobox/Listbox.tsx +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "20.1.
|
|
3
|
+
"version": "20.1.5",
|
|
4
4
|
"description": "React komponentbibliotek til Punkt, designsystem for Oslo kommune",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo kommune",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
103
103
|
},
|
|
104
104
|
"license": "MIT",
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "12b6f8cf53ddc1a50ff7d17dd7ceb70c068e058e"
|
|
106
106
|
}
|
|
@@ -176,6 +176,19 @@ describe('PktCombobox', () => {
|
|
|
176
176
|
const disabledOption = container.querySelector('[data-value="cherry"]')
|
|
177
177
|
expect(disabledOption?.getAttribute('data-disabled')).toBe('true')
|
|
178
178
|
})
|
|
179
|
+
|
|
180
|
+
test('shows empty list banner when there are no options', () => {
|
|
181
|
+
const { container } = createComboboxTest()
|
|
182
|
+
|
|
183
|
+
const banner = container.querySelector('.pkt-listbox__banner--empty')
|
|
184
|
+
expect(banner).toHaveTextContent('Tom liste')
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
test('hides empty list banner when listbox.empty is an empty string', () => {
|
|
188
|
+
const { container } = createComboboxTest({ strings: { listbox: { empty: '' } } })
|
|
189
|
+
|
|
190
|
+
expect(container.querySelector('.pkt-listbox__banner--empty')).not.toBeInTheDocument()
|
|
191
|
+
})
|
|
179
192
|
})
|
|
180
193
|
|
|
181
194
|
describe('Value handling', () => {
|
|
@@ -496,6 +496,41 @@ describe('PktCombobox', () => {
|
|
|
496
496
|
})
|
|
497
497
|
})
|
|
498
498
|
|
|
499
|
+
describe('Value added message', () => {
|
|
500
|
+
const addCustomValue = (props: Partial<IPktCombobox> = {}) => {
|
|
501
|
+
const handleValueChange = vi.fn()
|
|
502
|
+
const { container } = createComboboxTest({
|
|
503
|
+
allowUserInput: true,
|
|
504
|
+
options: getDefaultOptions(),
|
|
505
|
+
onValueChange: handleValueChange,
|
|
506
|
+
...props,
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
const textInput = container.querySelector('input[type="text"]') as HTMLInputElement
|
|
510
|
+
fireEvent.focus(textInput)
|
|
511
|
+
fireEvent.change(textInput, { target: { value: 'NewFruit' } })
|
|
512
|
+
fireEvent.keyDown(textInput, { key: 'Enter' })
|
|
513
|
+
|
|
514
|
+
return { container, handleValueChange }
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
test('shows value added message after adding a custom value', () => {
|
|
518
|
+
const { container } = addCustomValue()
|
|
519
|
+
|
|
520
|
+
const banner = container.querySelector('.pkt-listbox__banner--user-message')
|
|
521
|
+
expect(banner).toHaveTextContent('Ny verdi lagt til')
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
test('hides value added message when combobox.valueAdded is an empty string', () => {
|
|
525
|
+
const { container, handleValueChange } = addCustomValue({
|
|
526
|
+
strings: { combobox: { valueAdded: '' } },
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
expect(handleValueChange).toHaveBeenCalledWith(['NewFruit'])
|
|
530
|
+
expect(container.querySelector('.pkt-listbox__banner--user-message')).not.toBeInTheDocument()
|
|
531
|
+
})
|
|
532
|
+
})
|
|
533
|
+
|
|
499
534
|
describe('Children as options', () => {
|
|
500
535
|
test('handles options from children correctly', () => {
|
|
501
536
|
const handleValueChange = vi.fn()
|
|
@@ -41,6 +41,7 @@ export const Listbox = ({ state }: IListboxProps) => {
|
|
|
41
41
|
const showMaxBanner = multiple && selectedCount > 0 && maxlength != null && maxlength > 0
|
|
42
42
|
const showNewOptionBanner = allowUserInput && addValueText && !maxIsReached
|
|
43
43
|
const showUserMessage = !!userInfoMessage
|
|
44
|
+
const showEmptyBanner = !!s.listbox.empty && options.length === 0 && filteredOptions.length === 0 && !showUserMessage
|
|
44
45
|
|
|
45
46
|
const listboxClasses = ['pkt-listbox', isOpen && 'pkt-listbox__open', 'pkt-txt-16-light'].filter(Boolean).join(' ')
|
|
46
47
|
|
|
@@ -104,7 +105,7 @@ export const Listbox = ({ state }: IListboxProps) => {
|
|
|
104
105
|
</div>
|
|
105
106
|
)}
|
|
106
107
|
|
|
107
|
-
{
|
|
108
|
+
{showEmptyBanner && (
|
|
108
109
|
<div className="pkt-listbox__banner pkt-listbox__banner--empty">
|
|
109
110
|
<PktIcon className="pkt-listbox__banner-icon" name="exclamation-mark-circle" />
|
|
110
111
|
{s.listbox.empty}
|