@digdir/designsystemet-react 1.19.0 → 1.20.0

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.
@@ -4,7 +4,6 @@
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var react = require('react');
6
6
  var button = require('../button/button.js');
7
- var utilities = require('../Combobox/utilities.js');
8
7
 
9
8
  /**
10
9
  * SearchClear component, used to display a clear button when the search input is not empty.
@@ -15,23 +14,8 @@ var utilities = require('../Combobox/utilities.js');
15
14
  * <SearchClear />
16
15
  * </Search>
17
16
  */
18
- const SearchClear = react.forwardRef(function SearchClear({ 'aria-label': label = 'Tøm', onClick, ...rest }, ref) {
19
- const handleClear = (e) => {
20
- const target = e.target;
21
- let input = null;
22
- if (target instanceof HTMLElement)
23
- input = target.closest('.ds-search')?.querySelector('input');
24
- if (!input)
25
- throw new Error('Input is missing');
26
- /* narrow type to make TS happy */
27
- if (!(input instanceof HTMLInputElement))
28
- throw new Error('Input is not an input element');
29
- e.preventDefault();
30
- utilities.setReactInputValue(input, '');
31
- input.focus();
32
- onClick?.(e);
33
- };
34
- return (jsxRuntime.jsx(button.Button, { ref: ref, variant: 'tertiary', type: 'reset', "aria-label": label, onClick: handleClear, icon: true, ...rest }));
17
+ const SearchClear = react.forwardRef(function SearchClear({ 'aria-label': label = 'Tøm', ...rest }, ref) {
18
+ return (jsxRuntime.jsx(button.Button, { "aria-label": label, ref: ref, type: 'reset', variant: 'tertiary', ...rest }));
35
19
  });
36
20
 
37
21
  exports.SearchClear = SearchClear;
@@ -13,10 +13,8 @@ var input = require('../input/input.js');
13
13
  * <SearchInput aria-label='Søk' />
14
14
  * </Search>
15
15
  */
16
- const SearchInput = react.forwardRef(function SearchInput({ ...rest }, ref) {
17
- return (jsxRuntime.jsx(input.Input, { ref: ref, type: 'search',
18
- /* We need an empty placeholder for the clear button to be able to show/hide */
19
- placeholder: '', ...rest }));
16
+ const SearchInput = react.forwardRef(function SearchInput({ type = 'search', ...rest }, ref) {
17
+ return jsxRuntime.jsx(input.Input, { ref: ref, type: type, ...rest });
20
18
  });
21
19
 
22
20
  exports.SearchInput = SearchInput;
@@ -2,6 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
+ require('@digdir/designsystemet-web');
5
6
  var cl = require('clsx/lite');
6
7
  var react = require('react');
7
8
 
@@ -22,7 +23,8 @@ var react = require('react');
22
23
  * </Search>
23
24
  */
24
25
  const Search = react.forwardRef(function Search({ className, ...rest }, ref) {
25
- return jsxRuntime.jsx("div", { ref: ref, className: cl('ds-search', className), ...rest });
26
+ // Using "class" since React does not translate className on custom elements
27
+ return (jsxRuntime.jsx("ds-suggestion", { ref: ref, class: cl('ds-search', className), ...rest }));
26
28
  });
27
29
 
28
30
  exports.Search = Search;
@@ -47,11 +47,8 @@ const Suggestion = react.forwardRef(function Suggestion({ children, className, c
47
47
  const beforeChange = (event) => {
48
48
  event.preventDefault();
49
49
  const multiple = combobox?.multiple;
50
- const input = combobox?.control;
51
50
  const data = event.detail;
52
51
  const nextItem = nextItems(data, selectedItemsRef.current, multiple);
53
- if (!multiple && input)
54
- input.value = data?.textContent || ''; // Sync input value for single selection
55
52
  onSelectedChangeRef.current?.(nextItem || null);
56
53
  if (!isControlled)
57
54
  setDefaultItems(sanitizeItems(nextItem));
@@ -2,7 +2,6 @@
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { forwardRef } from 'react';
4
4
  import { Button } from '../button/button.js';
5
- import { setReactInputValue } from '../Combobox/utilities.js';
6
5
 
7
6
  /**
8
7
  * SearchClear component, used to display a clear button when the search input is not empty.
@@ -13,23 +12,8 @@ import { setReactInputValue } from '../Combobox/utilities.js';
13
12
  * <SearchClear />
14
13
  * </Search>
15
14
  */
16
- const SearchClear = forwardRef(function SearchClear({ 'aria-label': label = 'Tøm', onClick, ...rest }, ref) {
17
- const handleClear = (e) => {
18
- const target = e.target;
19
- let input = null;
20
- if (target instanceof HTMLElement)
21
- input = target.closest('.ds-search')?.querySelector('input');
22
- if (!input)
23
- throw new Error('Input is missing');
24
- /* narrow type to make TS happy */
25
- if (!(input instanceof HTMLInputElement))
26
- throw new Error('Input is not an input element');
27
- e.preventDefault();
28
- setReactInputValue(input, '');
29
- input.focus();
30
- onClick?.(e);
31
- };
32
- return (jsx(Button, { ref: ref, variant: 'tertiary', type: 'reset', "aria-label": label, onClick: handleClear, icon: true, ...rest }));
15
+ const SearchClear = forwardRef(function SearchClear({ 'aria-label': label = 'Tøm', ...rest }, ref) {
16
+ return (jsx(Button, { "aria-label": label, ref: ref, type: 'reset', variant: 'tertiary', ...rest }));
33
17
  });
34
18
 
35
19
  export { SearchClear };
@@ -11,10 +11,8 @@ import { Input } from '../input/input.js';
11
11
  * <SearchInput aria-label='Søk' />
12
12
  * </Search>
13
13
  */
14
- const SearchInput = forwardRef(function SearchInput({ ...rest }, ref) {
15
- return (jsx(Input, { ref: ref, type: 'search',
16
- /* We need an empty placeholder for the clear button to be able to show/hide */
17
- placeholder: '', ...rest }));
14
+ const SearchInput = forwardRef(function SearchInput({ type = 'search', ...rest }, ref) {
15
+ return jsx(Input, { ref: ref, type: type, ...rest });
18
16
  });
19
17
 
20
18
  export { SearchInput };
@@ -1,5 +1,6 @@
1
1
  'use client';
2
2
  import { jsx } from 'react/jsx-runtime';
3
+ import '@digdir/designsystemet-web';
3
4
  import cl from 'clsx/lite';
4
5
  import { forwardRef } from 'react';
5
6
 
@@ -20,7 +21,8 @@ import { forwardRef } from 'react';
20
21
  * </Search>
21
22
  */
22
23
  const Search = forwardRef(function Search({ className, ...rest }, ref) {
23
- return jsx("div", { ref: ref, className: cl('ds-search', className), ...rest });
24
+ // Using "class" since React does not translate className on custom elements
25
+ return (jsx("ds-suggestion", { ref: ref, class: cl('ds-search', className), ...rest }));
24
26
  });
25
27
 
26
28
  export { Search };
@@ -45,11 +45,8 @@ const Suggestion = forwardRef(function Suggestion({ children, className, creatab
45
45
  const beforeChange = (event) => {
46
46
  event.preventDefault();
47
47
  const multiple = combobox?.multiple;
48
- const input = combobox?.control;
49
48
  const data = event.detail;
50
49
  const nextItem = nextItems(data, selectedItemsRef.current, multiple);
51
- if (!multiple && input)
52
- input.value = data?.textContent || ''; // Sync input value for single selection
53
50
  onSelectedChangeRef.current?.(nextItem || null);
54
51
  if (!isControlled)
55
52
  setDefaultItems(sanitizeItems(nextItem));
@@ -1,6 +1,12 @@
1
1
  import { type InputHTMLAttributes } from 'react';
2
2
  import type { DefaultProps } from '../../types';
3
- export type SearchInputProps = DefaultProps & Omit<InputHTMLAttributes<HTMLInputElement>, 'readOnly' | 'type'>;
3
+ export type SearchInputProps = DefaultProps & Omit<InputHTMLAttributes<HTMLInputElement>, 'readOnly' | 'type'> & {
4
+ /**
5
+ * Type of input, affects if magnifying glass is shown or not. Use 'text' to hide magnifying glass.
6
+ * @default 'search'
7
+ */
8
+ type?: 'text' | 'search';
9
+ };
4
10
  /**
5
11
  * SearchInput component, used to display a search input within the Search component.
6
12
  *
@@ -9,4 +15,10 @@ export type SearchInputProps = DefaultProps & Omit<InputHTMLAttributes<HTMLInput
9
15
  * <SearchInput aria-label='Søk' />
10
16
  * </Search>
11
17
  */
12
- export declare const SearchInput: import("react").ForwardRefExoticComponent<DefaultProps & Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "readOnly"> & import("react").RefAttributes<HTMLInputElement>>;
18
+ export declare const SearchInput: import("react").ForwardRefExoticComponent<DefaultProps & Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "readOnly"> & {
19
+ /**
20
+ * Type of input, affects if magnifying glass is shown or not. Use 'text' to hide magnifying glass.
21
+ * @default 'search'
22
+ */
23
+ type?: "text" | "search";
24
+ } & import("react").RefAttributes<HTMLInputElement>>;
@@ -1,6 +1,8 @@
1
+ import '@digdir/designsystemet-web';
2
+ import type { DSSuggestionElement } from '@digdir/designsystemet-web';
1
3
  import { type HTMLAttributes } from 'react';
2
4
  import type { DefaultProps } from '../../types';
3
- export type SearchProps = DefaultProps & HTMLAttributes<HTMLDivElement>;
5
+ export type SearchProps = DefaultProps & HTMLAttributes<DSSuggestionElement>;
4
6
  /**
5
7
  * Search component, use to display different variations of a search input
6
8
  *
@@ -17,4 +19,4 @@ export type SearchProps = DefaultProps & HTMLAttributes<HTMLDivElement>;
17
19
  * <Search.Clear />
18
20
  * </Search>
19
21
  */
20
- export declare const Search: import("react").ForwardRefExoticComponent<DefaultProps & HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
22
+ export declare const Search: import("react").ForwardRefExoticComponent<DefaultProps & HTMLAttributes<DSSuggestionElement> & import("react").RefAttributes<DSSuggestionElement>>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@digdir/designsystemet-react",
3
3
  "type": "module",
4
- "version": "1.19.0",
4
+ "version": "1.20.0",
5
5
  "description": "React components for Designsystemet",
6
6
  "author": "Designsystemet team",
7
7
  "repository": {
@@ -41,16 +41,16 @@
41
41
  "@radix-ui/react-slot": "^1.3.3",
42
42
  "@tanstack/react-virtual": "^3.14.9",
43
43
  "clsx": "^2.1.1",
44
- "@digdir/designsystemet-types": "1.19.0",
45
- "@digdir/designsystemet-web": "1.19.0"
44
+ "@digdir/designsystemet-types": "1.20.0",
45
+ "@digdir/designsystemet-web": "1.20.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@rollup/plugin-commonjs": "29.0.3",
49
49
  "@rollup/plugin-node-resolve": "16.0.3",
50
- "@storybook/addon-docs": "10.5.6",
51
- "@storybook/addon-vitest": "10.5.6",
52
- "@storybook/react-vite": "10.5.6",
53
- "@testing-library/jest-dom": "7.0.0",
50
+ "@storybook/addon-docs": "10.5.7",
51
+ "@storybook/addon-vitest": "10.5.7",
52
+ "@storybook/react-vite": "10.5.7",
53
+ "@testing-library/jest-dom": "7.0.1",
54
54
  "@testing-library/react": "16.3.2",
55
55
  "@testing-library/user-event": "14.6.3",
56
56
  "@types/react": "19.2.18",
@@ -61,9 +61,9 @@
61
61
  "rimraf": "6.1.3",
62
62
  "rollup": "4.62.4",
63
63
  "rollup-plugin-copy": "3.5.0",
64
- "storybook": "10.5.6",
64
+ "storybook": "10.5.7",
65
65
  "typescript": "6.0.3",
66
- "@digdir/designsystemet-css": "^1.19.0"
66
+ "@digdir/designsystemet-css": "^1.20.0"
67
67
  },
68
68
  "scripts": {
69
69
  "build": "pnpm run clean && tsc -b tsconfig.lib.json --emitDeclarationOnly false && rollup -c --bundleConfigAsCjs",