@oslokommune/punkt-react 20.1.4 → 20.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "20.1.4",
3
+ "version": "20.1.6",
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": "3f146720edddb4d65cc1904790938c0858e9072a"
105
+ "gitHead": "6ef9d26f6ab0cb2451d44b2a586d32745d246a08"
106
106
  }
@@ -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()
@@ -49,11 +49,10 @@ describe('PktSelect', () => {
49
49
  })
50
50
 
51
51
  test('renders error message when hasError prop is true', async () => {
52
- render(
53
- <PktSelect label="Input Label" id="inputId" hasError errorMessage="Input error" />,
54
- )
52
+ render(<PktSelect label="Input Label" id="inputId" hasError errorMessage="Input error" />)
55
53
  const alertContainer = screen.getByRole('alert')
56
- const errorMessageId = 'inputId-input-error' // når https://github.com/oslokommune/punkt/issues/3092 er fiksa: screen.getByRole('combobox').getAttribute('aria-errormessage')
54
+ const errorMessageId = screen.getByRole('combobox').getAttribute('aria-errormessage')
55
+ expect(errorMessageId).toBe('inputId-input-error')
57
56
  expect(alertContainer).toHaveAttribute('id', errorMessageId)
58
57
  expect(alertContainer).toHaveTextContent('Input error')
59
58
  })
@@ -85,7 +85,7 @@ export const PktSelect = forwardRef(
85
85
  ref={ref}
86
86
  className={`pkt-input pkt-input--${inputSize} ${fullwidth ? 'pkt-input--fullwidth' : ''}`}
87
87
  aria-invalid={hasError}
88
- aria-errormessage={hasError ? `${id}-error` : undefined}
88
+ aria-errormessage={hasError ? `${id}-input-error` : undefined}
89
89
  aria-describedby={describedByIds({
90
90
  id: `${id}-input`,
91
91
  hasHelptext: !!helptext,