@oslokommune/punkt-react 11.12.3 → 11.12.8

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/components/accordion/Accordion.d.ts +1 -1
  3. package/dist/components/accordion/AccordionItem.d.ts +1 -1
  4. package/dist/components/alert/Alert.d.ts +1 -1
  5. package/dist/components/backlink/BackLink.d.ts +1 -1
  6. package/dist/components/breadcrumbs/Breadcrumbs.d.ts +1 -1
  7. package/dist/components/button/Button.d.ts +1 -1
  8. package/dist/components/checkbox/Checkbox.d.ts +1 -1
  9. package/dist/components/footer/Footer.d.ts +1 -1
  10. package/dist/components/footerSimple/FooterSimple.d.ts +1 -1
  11. package/dist/components/header/Header.d.ts +2 -2
  12. package/dist/components/icon/Icon.d.ts +1 -1
  13. package/dist/components/icon/IconContext.d.ts +1 -1
  14. package/dist/components/index.d.ts +4 -1
  15. package/dist/components/input/Input.d.ts +1 -1
  16. package/dist/components/inputwrapper/InputWrapper.d.ts +2 -2
  17. package/dist/components/linkcard/LinkCard.d.ts +1 -1
  18. package/dist/components/loader/Loader.d.ts +1 -1
  19. package/dist/components/messagebox/Messagebox.d.ts +1 -1
  20. package/dist/components/radio/RadioButton.d.ts +1 -1
  21. package/dist/components/searchinput/SearchInput.d.ts +1 -1
  22. package/dist/components/select/Select.d.ts +2 -2
  23. package/dist/components/table/Table.d.ts +7 -7
  24. package/dist/components/table/Table.test.d.ts +1 -1
  25. package/dist/components/table/TableBody.d.ts +7 -0
  26. package/dist/components/table/TableData.d.ts +1 -1
  27. package/dist/components/table/TableDataCell.d.ts +8 -0
  28. package/dist/components/table/TableHeader.d.ts +3 -2
  29. package/dist/components/table/TableHeaderCell.d.ts +7 -0
  30. package/dist/components/table/TableRow.d.ts +7 -0
  31. package/dist/components/tabs/Tabs.d.ts +1 -1
  32. package/dist/components/tag/Tag.d.ts +1 -1
  33. package/dist/components/textarea/Textarea.d.ts +2 -2
  34. package/dist/components/textinput/Textinput.d.ts +1 -1
  35. package/dist/punkt-react.es.js +1414 -1438
  36. package/dist/punkt-react.umd.js +22 -17
  37. package/package.json +14 -14
  38. package/src/components/accordion/Accordion.test.tsx +1 -1
  39. package/src/components/accordion/Accordion.tsx +0 -1
  40. package/src/components/checkbox/Checkbox.test.tsx +4 -10
  41. package/src/components/footer/Footer.test.tsx +11 -14
  42. package/src/components/footerSimple/FooterSimple.test.tsx +27 -30
  43. package/src/components/header/Header.test.tsx +4 -10
  44. package/src/components/header/Header.tsx +1 -1
  45. package/src/components/icon/Icon.test.tsx +3 -7
  46. package/src/components/index.ts +4 -1
  47. package/src/components/inputwrapper/InputWrapper.tsx +7 -27
  48. package/src/components/linkcard/LinkCard.test.tsx +4 -10
  49. package/src/components/loader/Loader.test.tsx +2 -4
  50. package/src/components/radio/RadioButton.test.tsx +45 -44
  51. package/src/components/searchinput/SearchInput.test.tsx +3 -5
  52. package/src/components/searchinput/SearchInput.tsx +9 -28
  53. package/src/components/select/Select.test.tsx +4 -13
  54. package/src/components/select/Select.tsx +1 -1
  55. package/src/components/table/Table.test.tsx +48 -89
  56. package/src/components/table/Table.tsx +24 -23
  57. package/src/components/table/TableBody.tsx +13 -0
  58. package/src/components/table/TableData.tsx +1 -1
  59. package/src/components/table/TableDataCell.tsx +19 -0
  60. package/src/components/table/TableHeader.tsx +8 -2
  61. package/src/components/table/TableHeaderCell.tsx +13 -0
  62. package/src/components/table/TableRow.tsx +13 -0
  63. package/src/components/tag/Tag.test.tsx +1 -1
  64. package/src/components/textarea/Textarea.test.tsx +4 -13
  65. package/src/components/textinput/Textinput.test.tsx +4 -13
  66. package/src/components/table/__snapshots__/Table.test.tsx.snap +0 -137
@@ -1,5 +1,5 @@
1
1
  // Test med axe https://www.npmjs.com/package/jest-axe
2
- import '@testing-library/jest-dom/extend-expect';
2
+ import '@testing-library/jest-dom'
3
3
 
4
4
  import { render, screen } from '@testing-library/react'
5
5
  import { axe, toHaveNoViolations } from 'jest-axe'
@@ -8,9 +8,7 @@ import { PktFooter } from './Footer'
8
8
 
9
9
  expect.extend(toHaveNoViolations)
10
10
 
11
-
12
11
  describe('PktFooterSimple', () => {
13
-
14
12
  const columnOne = {
15
13
  title: 'Column One',
16
14
  links: [
@@ -54,7 +52,6 @@ describe('PktFooterSimple', () => {
54
52
  },
55
53
  ]
56
54
 
57
-
58
55
  describe('basic rendering', () => {
59
56
  it('should render columns and social links', () => {
60
57
  render(<PktFooter columnOne={columnOne} columnTwo={columnTwo} socialLinks={socialLinks} />)
@@ -87,11 +84,11 @@ describe('PktFooterSimple', () => {
87
84
  const columnTwoTextElement = screen.getByText('Column Two Text')
88
85
  expect(columnTwoTextElement).toBeInTheDocument()
89
86
 
90
- const personvernLink = screen.getByText('Personvern og informasjonskapsler');
91
- expect(personvernLink).toBeInTheDocument();
87
+ const personvernLink = screen.getByText('Personvern og informasjonskapsler')
88
+ expect(personvernLink).toBeInTheDocument()
92
89
 
93
- const tilgjengelighetLink = screen.getByText('Tilgjengelighet');
94
- expect(tilgjengelighetLink).toBeInTheDocument();
90
+ const tilgjengelighetLink = screen.getByText('Tilgjengelighet')
91
+ expect(tilgjengelighetLink).toBeInTheDocument()
95
92
 
96
93
  const socialLinksElement = screen.getByLabelText('standard lenker')
97
94
  expect(socialLinksElement).toBeInTheDocument()
@@ -106,16 +103,16 @@ describe('PktFooterSimple', () => {
106
103
 
107
104
  describe('accessibility', () => {
108
105
  it('renders with no wcag errors with axe', async () => {
109
- const { container } = render(<PktFooter columnOne={columnOne} columnTwo={columnTwo} socialLinks={socialLinks} />);
110
- const results = await axe(container);
111
- expect(results).toHaveNoViolations();
106
+ const { container } = render(<PktFooter columnOne={columnOne} columnTwo={columnTwo} socialLinks={socialLinks} />)
107
+ const results = await axe(container)
108
+ expect(results).toHaveNoViolations()
112
109
  })
113
110
  })
114
111
 
115
112
  describe('snapshot', () => {
116
113
  it('renders correctly with all props', () => {
117
- const { container } = render(<PktFooter columnOne={columnOne} columnTwo={columnTwo} socialLinks={socialLinks} />);
118
- expect(container).toMatchSnapshot();
114
+ const { container } = render(<PktFooter columnOne={columnOne} columnTwo={columnTwo} socialLinks={socialLinks} />)
115
+ expect(container).toMatchSnapshot()
119
116
  })
120
117
  })
121
- });
118
+ })
@@ -1,5 +1,5 @@
1
1
  // Test med axe https://www.npmjs.com/package/jest-axe
2
- import '@testing-library/jest-dom/extend-expect';
2
+ import '@testing-library/jest-dom'
3
3
 
4
4
  import { render } from '@testing-library/react'
5
5
  import { axe, toHaveNoViolations } from 'jest-axe'
@@ -8,58 +8,55 @@ import { PktFooterSimple } from './FooterSimple'
8
8
 
9
9
  expect.extend(toHaveNoViolations)
10
10
 
11
-
12
-
13
11
  describe('PktFooterSimple', () => {
14
-
15
12
  const links = [
16
13
  { href: 'https://www.example.com', text: 'Example Link 1' },
17
14
  { href: 'https://www.example.com', text: 'Example Link 2' },
18
15
  { href: 'https://www.example.com', text: 'Example Link 3' },
19
- ];
16
+ ]
20
17
 
21
18
  describe('basic rendering', () => {
22
19
  it('renders a list of links', () => {
23
- const { getByText } = render(<PktFooterSimple links={links} />);
20
+ const { getByText } = render(<PktFooterSimple links={links} />)
24
21
  links.forEach((link) => {
25
- expect(getByText(link.text)).toBeInTheDocument();
26
- expect(getByText(link.text).getAttribute('href')).toEqual(link.href);
27
- });
28
- });
22
+ expect(getByText(link.text)).toBeInTheDocument()
23
+ expect(getByText(link.text).getAttribute('href')).toEqual(link.href)
24
+ })
25
+ })
29
26
 
30
27
  it('renders an external link with an external class', () => {
31
- const links = [
32
- { href: 'https://www.example.com', text: 'Example Link', external: true },
33
- ];
34
- const { getByText } = render(<PktFooterSimple links={links} />);
35
- expect(getByText(links[0].text)).toHaveClass('pkt-link--external');
36
- });
28
+ const links = [{ href: 'https://www.example.com', text: 'Example Link', external: true }]
29
+ const { getByText } = render(<PktFooterSimple links={links} />)
30
+ expect(getByText(links[0].text)).toHaveClass('pkt-link--external')
31
+ })
37
32
 
38
33
  it('renders a privacy link', () => {
39
- const { getByText } = render(<PktFooterSimple />);
40
- expect(getByText('Personvern og informasjonskapsler')).toBeInTheDocument();
41
- expect(getByText('Personvern og informasjonskapsler').getAttribute('href')).toEqual('https://www.oslo.kommune.no/personvern-og-informasjonskapsler/');
42
- });
34
+ const { getByText } = render(<PktFooterSimple />)
35
+ expect(getByText('Personvern og informasjonskapsler')).toBeInTheDocument()
36
+ expect(getByText('Personvern og informasjonskapsler').getAttribute('href')).toEqual(
37
+ 'https://www.oslo.kommune.no/personvern-og-informasjonskapsler/',
38
+ )
39
+ })
43
40
 
44
41
  it('renders an accessibility link', () => {
45
- const { getByText } = render(<PktFooterSimple />);
46
- expect(getByText('Tilgjengelighet')).toBeInTheDocument();
47
- expect(getByText('Tilgjengelighet').getAttribute('href')).toEqual('https://www.oslo.kommune.no/tilgjengelighet/');
48
- });
42
+ const { getByText } = render(<PktFooterSimple />)
43
+ expect(getByText('Tilgjengelighet')).toBeInTheDocument()
44
+ expect(getByText('Tilgjengelighet').getAttribute('href')).toEqual('https://www.oslo.kommune.no/tilgjengelighet/')
45
+ })
49
46
  })
50
47
 
51
48
  describe('accessibility', () => {
52
49
  it('renders with no wcag errors with axe', async () => {
53
- const { container } = render(<PktFooterSimple links={links} />);
54
- const results = await axe(container);
55
- expect(results).toHaveNoViolations();
50
+ const { container } = render(<PktFooterSimple links={links} />)
51
+ const results = await axe(container)
52
+ expect(results).toHaveNoViolations()
56
53
  })
57
54
  })
58
55
 
59
56
  describe('snapshot', () => {
60
57
  it('renders correctly with all props', () => {
61
- const { container } = render(<PktFooterSimple links={links} />);
62
- expect(container).toMatchSnapshot();
58
+ const { container } = render(<PktFooterSimple links={links} />)
59
+ expect(container).toMatchSnapshot()
63
60
  })
64
61
  })
65
- });
62
+ })
@@ -1,4 +1,4 @@
1
- import '@testing-library/jest-dom/extend-expect'
1
+ import '@testing-library/jest-dom'
2
2
 
3
3
  import { fireEvent, render, screen } from '@testing-library/react'
4
4
  import { axe, toHaveNoViolations } from 'jest-axe'
@@ -59,20 +59,14 @@ describe('PktHeader', () => {
59
59
  })
60
60
 
61
61
  it('toggles user menu when user button is clicked', () => {
62
- render(
63
- <PktHeader user={mockUser} userMenu={mockUserMenu} userMenuFooter={mockUserMenuFooter} />,
64
- )
62
+ render(<PktHeader user={mockUser} userMenu={mockUserMenu} userMenuFooter={mockUserMenuFooter} />)
65
63
  const userButton = screen.getByRole('button', { name: 'John Doe JD' })
66
64
  fireEvent.click(userButton)
67
65
  // Add assertions to check if user menu is open
68
- expect(screen.getByTestId('usermenu').classList.contains('pkt-header--open-dropdown')).toBe(
69
- true,
70
- )
66
+ expect(screen.getByTestId('usermenu').classList.contains('pkt-header--open-dropdown')).toBe(true)
71
67
  fireEvent.click(userButton)
72
68
  // Add assertions to check if user menu is closed
73
- expect(screen.getByTestId('usermenu').classList.contains('pkt-header--open-dropdown')).toBe(
74
- false,
75
- )
69
+ expect(screen.getByTestId('usermenu').classList.contains('pkt-header--open-dropdown')).toBe(false)
76
70
  })
77
71
 
78
72
  describe('accessibility', () => {
@@ -43,7 +43,7 @@ export interface IPktHeader extends HTMLAttributes<HTMLDivElement> {
43
43
  openMenu?: () => void
44
44
  logOut?: () => void
45
45
  changeRepresentation?: () => void
46
- children?: React.ReactNode
46
+ children?: React.ReactNode | React.ReactNode[]
47
47
  }
48
48
 
49
49
  export const PktHeader = forwardRef(
@@ -1,4 +1,4 @@
1
- import '@testing-library/jest-dom/extend-expect'
1
+ import '@testing-library/jest-dom'
2
2
 
3
3
  import { render, screen, waitFor } from '@testing-library/react'
4
4
  import React from 'react'
@@ -28,9 +28,7 @@ describe('PktIcon', () => {
28
28
 
29
29
  describe('with default fetcher', () => {
30
30
  test('fetches SVG with default fetcher', async () => {
31
- fetchSpy.mockResolvedValue(
32
- new Response('<svg role="img">arrow Her er noe SVG</svg>', { status: 200 }),
33
- )
31
+ fetchSpy.mockResolvedValue(new Response('<svg role="img">arrow Her er noe SVG</svg>', { status: 200 }))
34
32
 
35
33
  render(<PktIcon name={'arrow'} />)
36
34
 
@@ -46,9 +44,7 @@ describe('PktIcon', () => {
46
44
 
47
45
  test('fetches SVG', async () => {
48
46
  fetchSpy.mockImplementation(() =>
49
- Promise.resolve(
50
- new Response('<svg role="img">some-icon Her er noe SVG</svg>', { status: 200 }),
51
- ),
47
+ Promise.resolve(new Response('<svg role="img">some-icon Her er noe SVG</svg>', { status: 200 })),
52
48
  )
53
49
 
54
50
  render(
@@ -17,8 +17,11 @@ export { PktRadioButton } from './radio/RadioButton'
17
17
  export { PktSearchInput } from './searchinput/SearchInput'
18
18
  export { PktSelect } from './select/Select'
19
19
  export { PktTable } from './table/Table'
20
- export { PktTableData } from './table/TableData'
20
+ export { PktTableDataCell } from './table/TableDataCell'
21
+ export { PktTableHeaderCell } from './table/TableHeaderCell'
21
22
  export { PktTableHeader } from './table/TableHeader'
23
+ export { PktTableRow } from './table/TableRow'
24
+ export { PktTableBody } from './table/TableBody'
22
25
  export { PktTabs } from './tabs/Tabs'
23
26
  export { PktTag } from './tag/Tag'
24
27
  export { PktTextarea } from './textarea/Textarea'
@@ -19,7 +19,7 @@ export interface IPktInputWrapper extends RefAttributes<HTMLElement> {
19
19
  inline?: boolean
20
20
  ariaDescribedby?: string
21
21
  useWrapper?: boolean
22
- children?: ReactNode
22
+ children?: ReactNode | ReactNode[]
23
23
  className?: string
24
24
  hasFieldset?: boolean
25
25
  }
@@ -72,38 +72,23 @@ export const PktInputWrapper = forwardRef(
72
72
 
73
73
  const hasDropDown = !!helptextDropdown && helptextDropdown !== ''
74
74
 
75
- const dropdownButton =
76
- helptextDropdownButton || 'Les mer <span class="pkt-sr-only">om inputfeltet</span>'
75
+ const dropdownButton = helptextDropdownButton || 'Les mer <span class="pkt-sr-only">om inputfeltet</span>'
77
76
 
78
77
  const LabelComponent = hasFieldset ? 'fieldset' : hasDropDown ? 'div' : 'label'
79
78
  const LabelTextComponent = hasFieldset ? 'legend' : hasDropDown ? 'h2' : 'span'
80
79
 
81
- const describedBy = ariaDescribedby
82
- ? ariaDescribedby
83
- : helptext
84
- ? `${forId}-helptext`
85
- : undefined
80
+ const describedBy = ariaDescribedby ? ariaDescribedby : helptext ? `${forId}-helptext` : undefined
86
81
 
87
82
  return (
88
- <div
89
- className={['pkt-inputwrapper', className, disabledClass, inlineClass, errorClass].join(
90
- ' ',
91
- )}
92
- ref={ref}
93
- >
83
+ <div className={['pkt-inputwrapper', className, disabledClass, inlineClass, errorClass].join(' ')} ref={ref}>
94
84
  {useWrapper ? (
95
85
  <>
96
86
  <LabelComponent
97
87
  htmlFor={!hasFieldset ? forId : undefined}
98
88
  aria-describedby={hasDropDown ? undefined : ariaDescribedby}
99
- className={`pkt-inputwrapper__label${
100
- hasFieldset ? ' pkt-inputwrapper__fieldset' : ''
101
- }`}
89
+ className={`pkt-inputwrapper__label${hasFieldset ? ' pkt-inputwrapper__fieldset' : ''}`}
102
90
  >
103
- <LabelTextComponent
104
- id={`${forId}-label`}
105
- className={`${hasFieldset ? ' pkt-inputwrapper__legend' : ''}`}
106
- >
91
+ <LabelTextComponent id={`${forId}-label`} className={`${hasFieldset ? ' pkt-inputwrapper__legend' : ''}`}>
107
92
  {label}
108
93
  {tagText !== '' && <span className={tagClass()}>{tagText}</span>}
109
94
  </LabelTextComponent>
@@ -148,12 +133,7 @@ export const PktInputWrapper = forwardRef(
148
133
  ) : (
149
134
  <>
150
135
  {!hasFieldset && (
151
- <label
152
- htmlFor={forId}
153
- className="pkt-sr-only"
154
- aria-describedby={describedBy}
155
- id={`${forId}-label`}
156
- >
136
+ <label htmlFor={forId} className="pkt-sr-only" aria-describedby={describedBy} id={`${forId}-label`}>
157
137
  {label}
158
138
  </label>
159
139
  )}
@@ -1,5 +1,5 @@
1
1
  // Test med axe https://www.npmjs.com/package/jest-axe
2
- import '@testing-library/jest-dom/extend-expect';
2
+ import '@testing-library/jest-dom'
3
3
 
4
4
  import { render } from '@testing-library/react'
5
5
  import { axe, toHaveNoViolations } from 'jest-axe'
@@ -9,17 +9,13 @@ import { PktLinkCard } from './LinkCard'
9
9
 
10
10
  expect.extend(toHaveNoViolations)
11
11
 
12
-
13
-
14
12
  describe('PktLinkCard', () => {
15
-
16
13
  describe('basic rendering', () => {
17
-
18
14
  it('renders with title and content', () => {
19
15
  const { getByRole, getByText } = render(
20
16
  <PktLinkCard title="Link title" href="/example">
21
17
  Link content
22
- </PktLinkCard>
18
+ </PktLinkCard>,
23
19
  )
24
20
 
25
21
  expect(getByRole('link')).toHaveAttribute('href', '/example')
@@ -33,7 +29,6 @@ describe('PktLinkCard', () => {
33
29
  const linkElement = getByRole('link')
34
30
  expect(linkElement).toHaveAttribute('href', href)
35
31
  })
36
-
37
32
  })
38
33
 
39
34
  describe('skins', () => {
@@ -45,7 +40,7 @@ describe('PktLinkCard', () => {
45
40
  <PktLinkCard title="Beige" skin="beige" />
46
41
  <PktLinkCard title="Beige outline" skin="beige-outline" />
47
42
  <PktLinkCard title="Grey outline" skin="grey-outline" />
48
- </div>
43
+ </div>,
49
44
  )
50
45
 
51
46
  expect(container.querySelectorAll('.pkt-linkcard--normal')).toHaveLength(1)
@@ -70,10 +65,9 @@ describe('PktLinkCard', () => {
70
65
  const { asFragment } = render(
71
66
  <PktLinkCard title="Link title" href="/example">
72
67
  Link content
73
- </PktLinkCard>
68
+ </PktLinkCard>,
74
69
  )
75
70
  expect(asFragment()).toMatchSnapshot()
76
71
  })
77
72
  })
78
-
79
73
  })
@@ -1,4 +1,4 @@
1
- import '@testing-library/jest-dom/extend-expect'
1
+ import '@testing-library/jest-dom'
2
2
  import React from 'react'
3
3
 
4
4
  import { render } from '@testing-library/react'
@@ -15,9 +15,7 @@ describe('PktLoader', () => {
15
15
  })
16
16
 
17
17
  it('renders', () => {
18
- const { container } = render(
19
- <PktLoader size="medium" variant="rainbow" message="Loading.." />,
20
- )
18
+ const { container } = render(<PktLoader size="medium" variant="rainbow" message="Loading.." />)
21
19
  expect(container.firstChild).toHaveClass('pkt-loader--box')
22
20
  })
23
21
  it('renders inline', () => {
@@ -1,53 +1,54 @@
1
- import '@testing-library/jest-dom/extend-expect';
1
+ import '@testing-library/jest-dom'
2
2
 
3
- import { fireEvent, render } from '@testing-library/react';
3
+ import { fireEvent, render } from '@testing-library/react'
4
4
  import { axe, toHaveNoViolations } from 'jest-axe'
5
5
 
6
- import { PktRadioButton } from './RadioButton';
6
+ import { PktRadioButton } from './RadioButton'
7
7
 
8
8
  expect.extend(toHaveNoViolations)
9
9
 
10
10
  describe('PktRadiobutton', () => {
11
- // Test case for rendering a basic radiogroup
12
- it('renders without errors', () => {
13
- const { getByLabelText } = render(
14
- <div>
15
- <PktRadioButton id="radio1" name="radioGroup" label="Option 1" value="option1" />
16
- <PktRadioButton id="radio2" name="radioGroup" label="Option 2" value="option2" />
17
- </div>
18
- );
19
-
20
- expect(getByLabelText('Option 1')).toBeTruthy();
21
- expect(getByLabelText('Option 2')).toBeTruthy();
22
- });
23
-
24
- it('allows selecting one option from the group', () => {
25
- const { getByLabelText } = render(
26
- <div>
27
- <PktRadioButton id="radio1" name="radioGroup" label="Option 1" value="option1" />
28
- <PktRadioButton id="radio2" name="radioGroup" label="Option 2" value="option2" />
29
- </div>
30
- );
31
-
32
- const option1 = getByLabelText('Option 1') as HTMLInputElement;
33
- const option2 = getByLabelText('Option 2') as HTMLInputElement;
34
-
35
- fireEvent.click(option1);
36
- expect(option1.checked).toBe(true);
37
- expect(option2.checked).toBe(false);
38
-
39
- fireEvent.click(option2);
40
- expect(option1.checked).toBe(false);
41
- expect(option2.checked).toBe(true);
42
- });
43
-
44
-
45
- describe('accessibility', () => {
46
- it('renders with no wcag errors with axe', async () => {
47
- const { container } = render(<PktRadioButton name="accessibilitytest" id="accessibilityTest" label="My checkkbox" />)
48
- const results = await axe(container)
49
-
50
- expect(results).toHaveNoViolations()
51
- })
11
+ // Test case for rendering a basic radiogroup
12
+ it('renders without errors', () => {
13
+ const { getByLabelText } = render(
14
+ <div>
15
+ <PktRadioButton id="radio1" name="radioGroup" label="Option 1" value="option1" />
16
+ <PktRadioButton id="radio2" name="radioGroup" label="Option 2" value="option2" />
17
+ </div>,
18
+ )
19
+
20
+ expect(getByLabelText('Option 1')).toBeTruthy()
21
+ expect(getByLabelText('Option 2')).toBeTruthy()
22
+ })
23
+
24
+ it('allows selecting one option from the group', () => {
25
+ const { getByLabelText } = render(
26
+ <div>
27
+ <PktRadioButton id="radio1" name="radioGroup" label="Option 1" value="option1" />
28
+ <PktRadioButton id="radio2" name="radioGroup" label="Option 2" value="option2" />
29
+ </div>,
30
+ )
31
+
32
+ const option1 = getByLabelText('Option 1') as HTMLInputElement
33
+ const option2 = getByLabelText('Option 2') as HTMLInputElement
34
+
35
+ fireEvent.click(option1)
36
+ expect(option1.checked).toBe(true)
37
+ expect(option2.checked).toBe(false)
38
+
39
+ fireEvent.click(option2)
40
+ expect(option1.checked).toBe(false)
41
+ expect(option2.checked).toBe(true)
42
+ })
43
+
44
+ describe('accessibility', () => {
45
+ it('renders with no wcag errors with axe', async () => {
46
+ const { container } = render(
47
+ <PktRadioButton name="accessibilitytest" id="accessibilityTest" label="My checkkbox" />,
48
+ )
49
+ const results = await axe(container)
50
+
51
+ expect(results).toHaveNoViolations()
52
52
  })
53
+ })
53
54
  })
@@ -1,4 +1,4 @@
1
- import '@testing-library/jest-dom/extend-expect'
1
+ import '@testing-library/jest-dom'
2
2
 
3
3
  import { fireEvent, render, screen } from '@testing-library/react'
4
4
  import { axe, toHaveNoViolations } from 'jest-axe'
@@ -17,7 +17,7 @@ describe('PktSearchInput', () => {
17
17
  it('renders with div element when action prop does not exist', () => {
18
18
  const { container } = render(<PktSearchInput id="test-search-input" />)
19
19
  expect(container.querySelector('div')).toBeInTheDocument()
20
- expect(container.querySelector('form')).not.toBeInTheDocument();
20
+ expect(container.querySelector('form')).not.toBeInTheDocument()
21
21
  })
22
22
 
23
23
  it('renders with label element when label prop exists', () => {
@@ -70,9 +70,7 @@ describe('PktSearchInput', () => {
70
70
  { title: 'Suggestion 1', onClick: jest.fn() },
71
71
  { title: 'Suggestion 2', onClick: jest.fn() },
72
72
  ]
73
- const { container } = render(
74
- <PktSearchInput id="test-search-input" label="My label" suggestions={suggestions} />,
75
- )
73
+ const { container } = render(<PktSearchInput id="test-search-input" label="My label" suggestions={suggestions} />)
76
74
  const results = await axe(container)
77
75
  expect(results).toHaveNoViolations()
78
76
  })
@@ -70,21 +70,16 @@ export const PktSearchInput = forwardRef<HTMLFormElement & HTMLDivElement, ISear
70
70
  ref={ref}
71
71
  {...props}
72
72
  >
73
- <LabelElement
74
- htmlFor={label ? id : undefined}
75
- className={label ? 'pkt-inputwrapper__label' : ''}
76
- >
73
+ <LabelElement htmlFor={label ? id : undefined} className={label ? 'pkt-inputwrapper__label' : ''}>
77
74
  {label && <>{label}</>}
78
- <div
79
- className={appearance === 'local' ? 'pkt-input__container' : 'pkt-searchinput__field'}
80
- >
75
+ <div className={appearance === 'local' ? 'pkt-input__container' : 'pkt-searchinput__field'}>
81
76
  <input
82
77
  className={`pkt-input ${fullwidth ? 'pkt-input--fullwidth' : ''}`}
83
78
  type="search"
84
79
  name={name || id}
85
80
  id={id}
86
81
  placeholder={placeholder}
87
- value={value}
82
+ defaultValue={value}
88
83
  disabled={disabled}
89
84
  onInput={onSearch && ((event) => onSearch(event.currentTarget.value))}
90
85
  autoComplete="off"
@@ -92,9 +87,7 @@ export const PktSearchInput = forwardRef<HTMLFormElement & HTMLDivElement, ISear
92
87
  aria-controls={`${id}-suggestions`}
93
88
  />
94
89
  <PktButton
95
- className={`pkt-searchinput__button ${
96
- appearance === 'local' ? 'pkt-input-icon' : ''
97
- }`}
90
+ className={`pkt-searchinput__button ${appearance === 'local' ? 'pkt-input-icon' : ''}`}
98
91
  variant="icon-only"
99
92
  iconName="magnifying-glass-big"
100
93
  skin={appearance === 'local' ? 'tertiary' : 'primary'}
@@ -109,35 +102,23 @@ export const PktSearchInput = forwardRef<HTMLFormElement & HTMLDivElement, ISear
109
102
  </div>
110
103
  </LabelElement>
111
104
  {suggestions && (
112
- <ul
113
- id={`${id}-suggestions`}
114
- className="pkt-searchinput__suggestions"
115
- aria-live="assertive"
116
- >
105
+ <ul id={`${id}-suggestions`} className="pkt-searchinput__suggestions" aria-live="assertive">
117
106
  {suggestions.map((suggestion, index) => (
118
107
  <li key={`search-suggestion-${index}`}>
119
108
  {React.createElement(
120
109
  suggestion.href ? 'a' : suggestion.onClick ? 'button' : 'div',
121
110
  {
122
111
  href: suggestion.href,
123
- className: `pkt-searchinput__suggestion ${
124
- suggestion.onClick ? 'pkt-link-button' : ''
125
- } ${
126
- suggestion.href || suggestion.onClick
127
- ? 'pkt-searchinput__suggestion--has-hover'
128
- : ''
112
+ className: `pkt-searchinput__suggestion ${suggestion.onClick ? 'pkt-link-button' : ''} ${
113
+ suggestion.href || suggestion.onClick ? 'pkt-searchinput__suggestion--has-hover' : ''
129
114
  }`,
130
115
  type: suggestion.onClick ? 'button' : undefined,
131
116
  onClick: () => handleSuggestionClick(suggestion.onClick, index),
132
117
  onKeyUp: () => handleSuggestionClick(suggestion.onClick, index),
133
118
  },
134
119
  <>
135
- {suggestion.title && (
136
- <h3 className="pkt-searchinput__suggestion-title">{suggestion.title}</h3>
137
- )}
138
- {suggestion.text && (
139
- <p className="pkt-searchinput__suggestion-text">{suggestion.text}</p>
140
- )}
120
+ {suggestion.title && <h3 className="pkt-searchinput__suggestion-title">{suggestion.title}</h3>}
121
+ {suggestion.text && <p className="pkt-searchinput__suggestion-text">{suggestion.text}</p>}
141
122
  </>,
142
123
  )}
143
124
  </li>
@@ -1,4 +1,4 @@
1
- import '@testing-library/jest-dom/extend-expect'
1
+ import '@testing-library/jest-dom'
2
2
 
3
3
  import { fireEvent, render } from '@testing-library/react'
4
4
  import { axe, toHaveNoViolations } from 'jest-axe'
@@ -19,9 +19,7 @@ describe('PktSelect', () => {
19
19
  })
20
20
 
21
21
  test('renders error message when hasError prop is true', () => {
22
- const { getByText } = render(
23
- <PktSelect label="Input Label" id="inputId" hasError errorMessage="Input error" />,
24
- )
22
+ const { getByText } = render(<PktSelect label="Input Label" id="inputId" hasError errorMessage="Input error" />)
25
23
 
26
24
  const errorMessage = getByText('Input error')
27
25
  expect(errorMessage).toBeInTheDocument()
@@ -31,18 +29,11 @@ describe('PktSelect', () => {
31
29
  describe('PktSelect', () => {
32
30
  test('toggles helptext class', () => {
33
31
  const { getByText, container } = render(
34
- <PktSelect
35
- label="Input Label"
36
- id="inputId"
37
- helptext="Help Text"
38
- helptextDropdown="Help Text"
39
- />,
32
+ <PktSelect label="Input Label" id="inputId" helptext="Help Text" helptextDropdown="Help Text" />,
40
33
  )
41
34
 
42
35
  const expandButton = getByText('Les mer')
43
- const helptextElement = container.querySelector(
44
- '.pkt-inputwrapper__helptext-expandable-closed',
45
- )
36
+ const helptextElement = container.querySelector('.pkt-inputwrapper__helptext-expandable-closed')
46
37
 
47
38
  fireEvent.click(expandButton)
48
39
  expect(helptextElement).toHaveClass('pkt-inputwrapper__helptext-expandable-open')
@@ -5,7 +5,7 @@ import { PktInputWrapper } from '../inputwrapper/InputWrapper'
5
5
  export interface IPktSelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
6
6
  ariaDescribedby?: string
7
7
  ariaLabelledby?: string
8
- children?: ReactNode
8
+ children?: ReactNode | ReactNode[]
9
9
  disabled?: boolean
10
10
  errorMessage?: string
11
11
  hasError?: boolean