design-react-kit 5.9.3 → 5.11.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.
- package/CHANGELOG.md +19 -0
- package/dist/Accordion/AccordionBody.cjs +1 -1
- package/dist/Accordion/AccordionBody.cjs.map +1 -1
- package/dist/Autocomplete/Autocomplete.cjs +1 -1
- package/dist/Autocomplete/Autocomplete.cjs.map +1 -1
- package/dist/Autocomplete/Autocomplete.js +45 -6
- package/dist/Autocomplete/Autocomplete.js.map +1 -1
- package/dist/Collapse/Collapse.cjs +1 -1
- package/dist/Collapse/Collapse.cjs.map +1 -1
- package/dist/Collapse/Collapse.js +75 -7
- package/dist/Collapse/Collapse.js.map +1 -1
- package/dist/Input/Input.cjs +1 -1
- package/dist/Input/Input.cjs.map +1 -1
- package/dist/Input/Input.js +17 -19
- package/dist/Input/Input.js.map +1 -1
- package/dist/Input/InputContainer.cjs +1 -1
- package/dist/Input/InputContainer.cjs.map +1 -1
- package/dist/Input/InputContainer.js +3 -3
- package/dist/Input/InputContainer.js.map +1 -1
- package/dist/Input/TextArea.cjs +1 -1
- package/dist/Input/TextArea.cjs.map +1 -1
- package/dist/Input/TextArea.js +12 -4
- package/dist/Input/TextArea.js.map +1 -1
- package/dist/Input/utils.cjs +1 -1
- package/dist/Input/utils.cjs.map +1 -1
- package/dist/Modal/ModalHeader.cjs.map +1 -1
- package/dist/NavScroll/index.cjs +1 -1
- package/dist/NavScroll/index.cjs.map +1 -1
- package/dist/NavScroll/useNavScroll.cjs +1 -1
- package/dist/NavScroll/useNavScroll.cjs.map +1 -1
- package/dist/Progress/Progress.cjs +1 -1
- package/dist/Progress/Progress.cjs.map +1 -1
- package/dist/Rating/Rating.cjs +1 -1
- package/dist/Rating/Rating.cjs.map +1 -1
- package/dist/Section/Section.cjs +1 -1
- package/dist/Section/Section.cjs.map +1 -1
- package/dist/Transfer/Item.cjs +1 -1
- package/dist/Transfer/Item.cjs.map +1 -1
- package/dist/Transfer/SelectAllCheckbox.cjs +1 -1
- package/dist/Transfer/SelectAllCheckbox.cjs.map +1 -1
- package/dist/Transfer/Source.cjs +1 -1
- package/dist/Transfer/Source.cjs.map +1 -1
- package/dist/Transfer/Target.cjs +1 -1
- package/dist/Transfer/Target.cjs.map +1 -1
- package/dist/Transfer/Transfer.cjs +1 -1
- package/dist/Transfer/Transfer.cjs.map +1 -1
- package/dist/Upload/UploadListItem.cjs +1 -1
- package/dist/Upload/UploadListItem.cjs.map +1 -1
- package/dist/Video/Video.cjs +1 -1
- package/dist/Video/Video.cjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/types/Autocomplete/Autocomplete.d.ts +7 -1
- package/dist/types/Input/InputContainer.d.ts +1 -0
- package/dist/types/utils.d.ts +5 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +9 -0
- package/dist/utils.js.map +1 -1
- package/package.json +4 -5
- package/src/Autocomplete/Autocomplete.tsx +62 -7
- package/src/Collapse/Collapse.tsx +80 -7
- package/src/Input/Input.tsx +19 -20
- package/src/Input/InputContainer.tsx +8 -2
- package/src/Input/TextArea.tsx +13 -5
- package/src/utils.tsx +11 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
2
|
export interface AutocompleteAttributes {
|
|
3
3
|
/** Identificativo */
|
|
4
4
|
id: string;
|
|
5
5
|
/** Label */
|
|
6
6
|
label: string;
|
|
7
|
+
/** Minimo di caratteri per attivare l'autocomplete */
|
|
8
|
+
minLength?: number;
|
|
7
9
|
/** Valori all'interno della select */
|
|
8
10
|
source: (query: string, syncResults: () => void) => void;
|
|
9
11
|
/** Valori chiave - valore all'interno della select */
|
|
@@ -32,6 +34,10 @@ export interface AutocompleteAttributes {
|
|
|
32
34
|
tStatusResults?: () => string;
|
|
33
35
|
/** Classi aggiuntive da usare per il componente Button */
|
|
34
36
|
className?: string;
|
|
37
|
+
/** ID dei contenuti che descrivono il campo. */
|
|
38
|
+
'aria-describedby'?: string;
|
|
39
|
+
/** Stato di non validità fornito dal consumer. */
|
|
40
|
+
'aria-invalid'?: React.AriaAttributes['aria-invalid'];
|
|
35
41
|
testId?: string;
|
|
36
42
|
}
|
|
37
43
|
export declare const Autocomplete: FC<AutocompleteAttributes>;
|
|
@@ -6,6 +6,7 @@ export interface InputContainerProps extends HTMLAttributes<HTMLElement> {
|
|
|
6
6
|
validationTextClass: string;
|
|
7
7
|
label: string | ReactNode | undefined;
|
|
8
8
|
validationText: string | undefined;
|
|
9
|
+
errorId?: string;
|
|
9
10
|
id: string | undefined;
|
|
10
11
|
infoId: string | undefined;
|
|
11
12
|
infoText: string | undefined;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export declare const notifyDeprecation: (message: string, options?: {
|
|
|
5
5
|
once: boolean;
|
|
6
6
|
}) => void;
|
|
7
7
|
export declare function mapToCssModules(className: string | null, cssModules?: Record<string, string>): string;
|
|
8
|
+
/**
|
|
9
|
+
* Combines ID reference lists for `aria-describedby` without losing a
|
|
10
|
+
* description that was already supplied by the consumer.
|
|
11
|
+
*/
|
|
12
|
+
export declare function mergeAriaDescribedBy(...descriptions: Array<string | undefined | null>): string | undefined;
|
|
8
13
|
type UnknownObject = Record<string, unknown>;
|
|
9
14
|
export declare function pick<T extends UnknownObject>(obj: T, keys: keyof T | Array<keyof T>): Partial<T>;
|
|
10
15
|
export declare function omit<T extends UnknownObject>(obj: T, keys: keyof T | Array<keyof T>): Partial<T>;
|
package/dist/utils.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var u=(n,o)=>{for(var r in o)s(n,r,{get:o[r],enumerable:!0})},p=(n,o,r,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of l(o))!a.call(n,t)&&t!==r&&s(n,t,{get:()=>o[t],enumerable:!(e=f(o,t))||e.enumerable});return n};var y=n=>p(s({},"__esModule",{value:!0}),n);var b={};u(b,{flushMessageCache:()=>T,logError:()=>c,mapToCssModules:()=>k,mergeAriaDescribedBy:()=>x,noop:()=>d,notifyDeprecation:()=>g,omit:()=>w,pick:()=>A});module.exports=y(b);var d=()=>{},c=n=>{typeof console<"u"&&(console.error?console.error(n):console.log(n))},T=()=>{for(let n in i)delete i[n]},i={},g=(n,o={once:!0})=>{o.once?i[n]||(c(n),i[n]=1):c(n)};function k(n,o){let r=n??"";return o?r.split(" ").map(e=>o[e]??e).join(" "):r}function x(...n){let o=n.flatMap(e=>e?.trim().split(/\s+/)??[]),r=[...new Set(o.filter(Boolean))];return r.length>0?r.join(" "):void 0}function A(n,o){let r=Array.isArray(o)?o:[o],e={};for(let t of r)t in n&&(e[t]=n[t]);return e}function w(n,o){let r=new Set(Array.isArray(o)?o:[o]),e={};for(let t in n)r.has(t)||(e[t]=n[t]);return e}0&&(module.exports={flushMessageCache,logError,mapToCssModules,mergeAriaDescribedBy,noop,notifyDeprecation,omit,pick});
|
|
2
2
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.tsx"],"sourcesContent":["export const noop = () => {};\n\nexport const logError = (message: string) => {\n if (typeof console !== 'undefined') {\n if (console.error) {\n console.error(message);\n } else {\n console.log(message);\n }\n }\n};\n\n// @internal Used for testing purposes only\nexport const flushMessageCache = () => {\n for (const key in messages) {\n delete messages[key];\n }\n};\n\nconst messages: Record<string, 1> = {};\nexport const notifyDeprecation = (message: string, options: { once: boolean } = { once: true }) => {\n if (!options.once) {\n logError(message);\n } else {\n if (!messages[message]) {\n logError(message);\n messages[message] = 1;\n }\n }\n};\n\nexport function mapToCssModules(className: string | null, cssModules?: Record<string, string>) {\n const finalClassNames = className == null ? '' : className;\n if (!cssModules) {\n return finalClassNames;\n }\n return finalClassNames\n .split(' ')\n .map((klass) => cssModules[klass] ?? klass)\n .join(' ');\n}\n\ntype UnknownObject = Record<string, unknown>;\n\nexport function pick<T extends UnknownObject>(obj: T, keys: keyof T | Array<keyof T>): Partial<T> {\n const keysArray = Array.isArray(keys) ? keys : [keys];\n const newObj: Partial<T> = {};\n for (const key of keysArray) {\n if (key in obj) {\n newObj[key] = obj[key];\n }\n }\n return newObj;\n}\n\nexport function omit<T extends UnknownObject>(obj: T, keys: keyof T | Array<keyof T>): Partial<T> {\n const keysLookup = new Set(Array.isArray(keys) ? keys : [keys]);\n\n const newObj: Partial<T> = {};\n for (const key in obj) {\n if (!keysLookup.has(key)) {\n newObj[key] = obj[key];\n }\n }\n return newObj;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,aAAAC,EAAA,oBAAAC,EAAA,SAAAC,EAAA,sBAAAC,EAAA,SAAAC,EAAA,SAAAC,IAAA,eAAAC,
|
|
1
|
+
{"version":3,"sources":["../src/utils.tsx"],"sourcesContent":["export const noop = () => {};\n\nexport const logError = (message: string) => {\n if (typeof console !== 'undefined') {\n if (console.error) {\n console.error(message);\n } else {\n console.log(message);\n }\n }\n};\n\n// @internal Used for testing purposes only\nexport const flushMessageCache = () => {\n for (const key in messages) {\n delete messages[key];\n }\n};\n\nconst messages: Record<string, 1> = {};\nexport const notifyDeprecation = (message: string, options: { once: boolean } = { once: true }) => {\n if (!options.once) {\n logError(message);\n } else {\n if (!messages[message]) {\n logError(message);\n messages[message] = 1;\n }\n }\n};\n\nexport function mapToCssModules(className: string | null, cssModules?: Record<string, string>) {\n const finalClassNames = className == null ? '' : className;\n if (!cssModules) {\n return finalClassNames;\n }\n return finalClassNames\n .split(' ')\n .map((klass) => cssModules[klass] ?? klass)\n .join(' ');\n}\n\n/**\n * Combines ID reference lists for `aria-describedby` without losing a\n * description that was already supplied by the consumer.\n */\nexport function mergeAriaDescribedBy(...descriptions: Array<string | undefined | null>) {\n const ids = descriptions.flatMap((description) => description?.trim().split(/\\s+/) ?? []);\n const uniqueIds = [...new Set(ids.filter(Boolean))];\n\n return uniqueIds.length > 0 ? uniqueIds.join(' ') : undefined;\n}\n\ntype UnknownObject = Record<string, unknown>;\n\nexport function pick<T extends UnknownObject>(obj: T, keys: keyof T | Array<keyof T>): Partial<T> {\n const keysArray = Array.isArray(keys) ? keys : [keys];\n const newObj: Partial<T> = {};\n for (const key of keysArray) {\n if (key in obj) {\n newObj[key] = obj[key];\n }\n }\n return newObj;\n}\n\nexport function omit<T extends UnknownObject>(obj: T, keys: keyof T | Array<keyof T>): Partial<T> {\n const keysLookup = new Set(Array.isArray(keys) ? keys : [keys]);\n\n const newObj: Partial<T> = {};\n for (const key in obj) {\n if (!keysLookup.has(key)) {\n newObj[key] = obj[key];\n }\n }\n return newObj;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,aAAAC,EAAA,oBAAAC,EAAA,yBAAAC,EAAA,SAAAC,EAAA,sBAAAC,EAAA,SAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAV,GAAO,IAAMM,EAAO,IAAM,CAAC,EAEdH,EAAYQ,GAAoB,CACvC,OAAO,QAAY,MACjB,QAAQ,MACV,QAAQ,MAAMA,CAAO,EAErB,QAAQ,IAAIA,CAAO,EAGzB,EAGaT,EAAoB,IAAM,CACrC,QAAWU,KAAOC,EAChB,OAAOA,EAASD,CAAG,CAEvB,EAEMC,EAA8B,CAAC,EACxBN,EAAoB,CAACI,EAAiBG,EAA6B,CAAE,KAAM,EAAK,IAAM,CAC5FA,EAAQ,KAGND,EAASF,CAAO,IACnBR,EAASQ,CAAO,EAChBE,EAASF,CAAO,EAAI,GAJtBR,EAASQ,CAAO,CAOpB,EAEO,SAASP,EAAgBW,EAA0BC,EAAqC,CAC7F,IAAMC,EAAkBF,GAAoB,GAC5C,OAAKC,EAGEC,EACJ,MAAM,GAAG,EACT,IAAKC,GAAUF,EAAWE,CAAK,GAAKA,CAAK,EACzC,KAAK,GAAG,EALFD,CAMX,CAMO,SAASZ,KAAwBc,EAAgD,CACtF,IAAMC,EAAMD,EAAa,QAASE,GAAgBA,GAAa,KAAK,EAAE,MAAM,KAAK,GAAK,CAAC,CAAC,EAClFC,EAAY,CAAC,GAAG,IAAI,IAAIF,EAAI,OAAO,OAAO,CAAC,CAAC,EAElD,OAAOE,EAAU,OAAS,EAAIA,EAAU,KAAK,GAAG,EAAI,MACtD,CAIO,SAASb,EAA8Bc,EAAQC,EAA4C,CAChG,IAAMC,EAAY,MAAM,QAAQD,CAAI,EAAIA,EAAO,CAACA,CAAI,EAC9CE,EAAqB,CAAC,EAC5B,QAAWd,KAAOa,EACZb,KAAOW,IACTG,EAAOd,CAAG,EAAIW,EAAIX,CAAG,GAGzB,OAAOc,CACT,CAEO,SAASlB,EAA8Be,EAAQC,EAA4C,CAChG,IAAMG,EAAa,IAAI,IAAI,MAAM,QAAQH,CAAI,EAAIA,EAAO,CAACA,CAAI,CAAC,EAExDE,EAAqB,CAAC,EAC5B,QAAWd,KAAOW,EACXI,EAAW,IAAIf,CAAG,IACrBc,EAAOd,CAAG,EAAIW,EAAIX,CAAG,GAGzB,OAAOc,CACT","names":["utils_exports","__export","flushMessageCache","logError","mapToCssModules","mergeAriaDescribedBy","noop","notifyDeprecation","omit","pick","__toCommonJS","message","key","messages","options","className","cssModules","finalClassNames","klass","descriptions","ids","description","uniqueIds","obj","keys","keysArray","newObj","keysLookup"]}
|
package/dist/utils.js
CHANGED
|
@@ -37,6 +37,15 @@ export function mapToCssModules(className, cssModules) {
|
|
|
37
37
|
.map((klass) => cssModules[klass] ?? klass)
|
|
38
38
|
.join(' ');
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Combines ID reference lists for `aria-describedby` without losing a
|
|
42
|
+
* description that was already supplied by the consumer.
|
|
43
|
+
*/
|
|
44
|
+
export function mergeAriaDescribedBy(...descriptions) {
|
|
45
|
+
const ids = descriptions.flatMap((description) => description?.trim().split(/\s+/) ?? []);
|
|
46
|
+
const uniqueIds = [...new Set(ids.filter(Boolean))];
|
|
47
|
+
return uniqueIds.length > 0 ? uniqueIds.join(' ') : undefined;
|
|
48
|
+
}
|
|
40
49
|
export function pick(obj, keys) {
|
|
41
50
|
const keysArray = Array.isArray(keys) ? keys : [keys];
|
|
42
51
|
const newObj = {};
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAE7B,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,EAAE;IAC1C,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACnC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,2CAA2C;AAC3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAsB,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,UAA6B,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE;IAChG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAClB,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;SAAM,CAAC;Q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AC5B,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;YACf,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,IAAI,CAA0B,GAAM,EAAE,IAA8B;IAClF,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAEhE,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/italia/design-react-kit/issues"
|
|
27
27
|
},
|
|
28
|
-
"version": "5.
|
|
28
|
+
"version": "5.11.0",
|
|
29
29
|
"license": "BSD-3",
|
|
30
30
|
"type": "module",
|
|
31
31
|
"module": "./dist/index.js",
|
|
@@ -67,12 +67,11 @@
|
|
|
67
67
|
"storybook:serve": "storybook dev -p 9001",
|
|
68
68
|
"storybook:build": "storybook build --docs",
|
|
69
69
|
"storybook:build:base": "storybook build",
|
|
70
|
-
"storybook:deploy": "npx gh-pages -d storybook-static -m 'chore: update documentation [ci skip]' --nojekyll",
|
|
71
70
|
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && node scripts/wait-confirm && git add CHANGELOG.md",
|
|
72
71
|
"postversion": "echo \"You can now publish your version using 'git push --follow-tags'\""
|
|
73
72
|
},
|
|
74
73
|
"peerDependencies": {
|
|
75
|
-
"bootstrap-italia": "^2.
|
|
74
|
+
"bootstrap-italia": "^2.18.3",
|
|
76
75
|
"react": ">=18.2.0"
|
|
77
76
|
},
|
|
78
77
|
"browserslist": [
|
|
@@ -105,7 +104,7 @@
|
|
|
105
104
|
"@types/react-dom": "^18.2.24",
|
|
106
105
|
"@types/react-transition-group": "^4.4.10",
|
|
107
106
|
"@types/uuid": "^10.0.0",
|
|
108
|
-
"bootstrap-italia": "^2.
|
|
107
|
+
"bootstrap-italia": "^2.18.3",
|
|
109
108
|
"browserslist-config-design-italia": "^1.0.0",
|
|
110
109
|
"conventional-changelog": "^7.1.1",
|
|
111
110
|
"eslint": "^9.10.0",
|
|
@@ -132,7 +131,7 @@
|
|
|
132
131
|
"typeface-roboto-mono": "^1.1.13",
|
|
133
132
|
"typescript": "^5.4.5",
|
|
134
133
|
"typescript-eslint": "^8.4.0",
|
|
135
|
-
"vite": "^
|
|
134
|
+
"vite": "^6.4.2"
|
|
136
135
|
},
|
|
137
136
|
"dependencies": {
|
|
138
137
|
"@splidejs/react-splide": "^0.7.12",
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import React, { FC, useEffect } from 'react';
|
|
2
2
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
3
|
// @ts-ignore non ci sono i types
|
|
4
|
-
import
|
|
4
|
+
import AccessibleAutocomplete from 'accessible-autocomplete/react';
|
|
5
|
+
import { mergeAriaDescribedBy } from '../utils';
|
|
6
|
+
|
|
7
|
+
// accessible-autocomplete/react è un bundle UMD: alcuni bundler (es. Vite 8 con Rolldown) restituiscono
|
|
8
|
+
// l'oggetto del modulo invece del componente, quindi si prende `default` quando c'è
|
|
9
|
+
const BaseAutocomplete = AccessibleAutocomplete.default ?? AccessibleAutocomplete;
|
|
5
10
|
// Reference to https://www.npmjs.com/package/accessible-autocomplete
|
|
6
11
|
// Implementation example: https://github.com/alphagov/accessible-autocomplete/blob/main/examples/react/index.html
|
|
7
12
|
|
|
@@ -10,6 +15,8 @@ export interface AutocompleteAttributes {
|
|
|
10
15
|
id: string;
|
|
11
16
|
/** Label */
|
|
12
17
|
label: string;
|
|
18
|
+
/** Minimo di caratteri per attivare l'autocomplete */
|
|
19
|
+
minLength?: number;
|
|
13
20
|
/** Valori all'interno della select */
|
|
14
21
|
source: (query: string, syncResults: () => void) => void;
|
|
15
22
|
/** Valori chiave - valore all'interno della select */
|
|
@@ -38,6 +45,10 @@ export interface AutocompleteAttributes {
|
|
|
38
45
|
tStatusResults?: () => string;
|
|
39
46
|
/** Classi aggiuntive da usare per il componente Button */
|
|
40
47
|
className?: string;
|
|
48
|
+
/** ID dei contenuti che descrivono il campo. */
|
|
49
|
+
'aria-describedby'?: string;
|
|
50
|
+
/** Stato di non validità fornito dal consumer. */
|
|
51
|
+
'aria-invalid'?: React.AriaAttributes['aria-invalid'];
|
|
41
52
|
testId?: string;
|
|
42
53
|
}
|
|
43
54
|
|
|
@@ -60,6 +71,8 @@ const tStatusResultsDefault = (length: number, contentSelectedOption: number) =>
|
|
|
60
71
|
};
|
|
61
72
|
|
|
62
73
|
export const Autocomplete: FC<AutocompleteAttributes> = ({
|
|
74
|
+
id,
|
|
75
|
+
label,
|
|
63
76
|
tAssistiveHint = tAssistiveHintDefault,
|
|
64
77
|
tNoResults = tNoResultsDefault,
|
|
65
78
|
tStatusQueryTooShort = tStatusQueryTooShortDefault,
|
|
@@ -68,14 +81,17 @@ export const Autocomplete: FC<AutocompleteAttributes> = ({
|
|
|
68
81
|
tStatusResults = tStatusResultsDefault,
|
|
69
82
|
placeholder = '',
|
|
70
83
|
defaultValue = '',
|
|
84
|
+
minLength = 0,
|
|
71
85
|
displayMenu = 'inline',
|
|
72
86
|
source,
|
|
73
87
|
validationText,
|
|
74
88
|
onConfirm,
|
|
75
|
-
|
|
89
|
+
valid,
|
|
90
|
+
'aria-describedby': ariaDescribedBy,
|
|
91
|
+
'aria-invalid': ariaInvalid
|
|
76
92
|
}) => {
|
|
77
|
-
const { id, valid } = attributes;
|
|
78
93
|
const validityCheck = valid === true || valid === false;
|
|
94
|
+
const errorId = valid === false ? `${id}-error` : undefined;
|
|
79
95
|
|
|
80
96
|
useEffect(() => {
|
|
81
97
|
const inputElement: HTMLInputElement = document.getElementById(id) as HTMLInputElement;
|
|
@@ -98,17 +114,57 @@ export const Autocomplete: FC<AutocompleteAttributes> = ({
|
|
|
98
114
|
});
|
|
99
115
|
}, [id]);
|
|
100
116
|
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
const inputElement: HTMLInputElement = document.getElementById(id) as HTMLInputElement;
|
|
119
|
+
if (!inputElement) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const updateAccessibilityAttributes = () => {
|
|
124
|
+
const existingDescription = inputElement.getAttribute('aria-describedby');
|
|
125
|
+
const descriptionsWithoutError = existingDescription
|
|
126
|
+
?.split(/\s+/)
|
|
127
|
+
.filter((description) => description !== `${id}-error`)
|
|
128
|
+
.join(' ');
|
|
129
|
+
const describedBy = mergeAriaDescribedBy(ariaDescribedBy, descriptionsWithoutError, errorId);
|
|
130
|
+
|
|
131
|
+
if (describedBy && existingDescription !== describedBy) {
|
|
132
|
+
inputElement.setAttribute('aria-describedby', describedBy);
|
|
133
|
+
}
|
|
134
|
+
if (!describedBy && existingDescription) {
|
|
135
|
+
inputElement.removeAttribute('aria-describedby');
|
|
136
|
+
}
|
|
137
|
+
if (valid === false) {
|
|
138
|
+
inputElement.setAttribute('aria-invalid', 'true');
|
|
139
|
+
} else if (ariaInvalid !== undefined) {
|
|
140
|
+
inputElement.setAttribute('aria-invalid', String(ariaInvalid));
|
|
141
|
+
} else {
|
|
142
|
+
inputElement.removeAttribute('aria-invalid');
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
updateAccessibilityAttributes();
|
|
147
|
+
const observer = new MutationObserver(updateAccessibilityAttributes);
|
|
148
|
+
observer.observe(inputElement, { attributes: true, attributeFilter: ['aria-describedby'] });
|
|
149
|
+
|
|
150
|
+
return () => {
|
|
151
|
+
observer.disconnect();
|
|
152
|
+
};
|
|
153
|
+
}, [ariaDescribedBy, ariaInvalid, errorId, id, valid]);
|
|
154
|
+
|
|
101
155
|
return (
|
|
102
156
|
<>
|
|
103
|
-
<label htmlFor={
|
|
157
|
+
<label htmlFor={id}>{label}</label>
|
|
104
158
|
<BaseAutocomplete
|
|
159
|
+
id={id}
|
|
105
160
|
source={source}
|
|
106
161
|
placeholder={placeholder}
|
|
107
162
|
defaultValue={defaultValue}
|
|
163
|
+
minLength={minLength}
|
|
108
164
|
displayMenu={displayMenu}
|
|
109
165
|
tAssistiveHint={tAssistiveHint}
|
|
110
166
|
tNoResults={tNoResults}
|
|
111
|
-
tStatusQueryTooShort={tStatusQueryTooShort}
|
|
167
|
+
tStatusQueryTooShort={() => tStatusQueryTooShort(minLength)}
|
|
112
168
|
tStatusNoResults={tStatusNoResults}
|
|
113
169
|
tStatusSelectedOption={tStatusSelectedOption}
|
|
114
170
|
tStatusResults={tStatusResults}
|
|
@@ -122,9 +178,8 @@ export const Autocomplete: FC<AutocompleteAttributes> = ({
|
|
|
122
178
|
confirmOnBlur={false}
|
|
123
179
|
menuAttributes={null}
|
|
124
180
|
menuClasses={null}
|
|
125
|
-
{...attributes}
|
|
126
181
|
/>
|
|
127
|
-
<div className='form-feedback just-validate-error-label form-text form-feedback just-validate-error-label'>
|
|
182
|
+
<div id={errorId} className='form-feedback just-validate-error-label form-text form-feedback just-validate-error-label'>
|
|
128
183
|
{!valid && validationText}
|
|
129
184
|
</div>
|
|
130
185
|
</>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import React, { ElementType, FC, HTMLAttributes, Ref } from 'react';
|
|
2
|
+
import React, { ElementType, FC, HTMLAttributes, Ref, useEffect, useRef, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
import { Collapse as CollapseBase } from 'reactstrap';
|
|
5
5
|
import { CSSModule } from 'reactstrap/types/lib/utils';
|
|
@@ -63,25 +63,98 @@ export const Collapse: FC<CollapseProps> = ({
|
|
|
63
63
|
'navbar-collapse': 'navbar-collapsable',
|
|
64
64
|
...cssModule
|
|
65
65
|
};
|
|
66
|
+
|
|
67
|
+
// Two-phase state to allow CSS transitions to play.
|
|
68
|
+
// isVisible controls display:block/none; isExpanded controls the animation class.
|
|
69
|
+
const [isVisible, setIsVisible] = useState(isOpen);
|
|
70
|
+
const [isExpanded, setIsExpanded] = useState(isOpen);
|
|
71
|
+
const panelRef = useRef<HTMLElement>(null);
|
|
72
|
+
const triggerRef = useRef<Element | null>(null);
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (!(megamenu || navbar)) return;
|
|
76
|
+
if (isOpen) {
|
|
77
|
+
triggerRef.current = document.activeElement;
|
|
78
|
+
setIsVisible(true);
|
|
79
|
+
// Double rAF ensures the browser has painted display:block before adding
|
|
80
|
+
// the expanded class, so the CSS transform transition can fire.
|
|
81
|
+
requestAnimationFrame(() => {
|
|
82
|
+
requestAnimationFrame(() => {
|
|
83
|
+
setIsExpanded(true);
|
|
84
|
+
panelRef.current?.focus();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
setIsExpanded(false);
|
|
90
|
+
// Wait for the CSS transition to complete before hiding.
|
|
91
|
+
const timer = setTimeout(() => {
|
|
92
|
+
setIsVisible(false);
|
|
93
|
+
(triggerRef.current as HTMLElement | null)?.focus();
|
|
94
|
+
}, PANEL_TRANSITION_MS);
|
|
95
|
+
return () => clearTimeout(timer);
|
|
96
|
+
}, [isOpen, megamenu, navbar]);
|
|
97
|
+
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (!(megamenu || navbar)) return;
|
|
100
|
+
if (isOpen) {
|
|
101
|
+
document.body.style.overflow = 'hidden';
|
|
102
|
+
} else {
|
|
103
|
+
document.body.style.overflow = '';
|
|
104
|
+
}
|
|
105
|
+
return () => { document.body.style.overflow = ''; };
|
|
106
|
+
}, [isOpen, megamenu, navbar]);
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (!(megamenu || navbar)) return;
|
|
110
|
+
const main = document.querySelector('main');
|
|
111
|
+
if (!main) return;
|
|
112
|
+
if (isOpen) {
|
|
113
|
+
main.setAttribute('inert', '');
|
|
114
|
+
} else {
|
|
115
|
+
main.removeAttribute('inert');
|
|
116
|
+
}
|
|
117
|
+
return () => main.removeAttribute('inert');
|
|
118
|
+
}, [isOpen, megamenu, navbar]);
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (!(megamenu || navbar)) return;
|
|
122
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
123
|
+
if (e.key === 'Escape' && isOpen) {
|
|
124
|
+
onOverlayClick?.();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
128
|
+
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
129
|
+
}, [isOpen, megamenu, navbar, onOverlayClick]);
|
|
130
|
+
|
|
131
|
+
// Must match the longest CSS transition on .navbar-collapsable (currently 0.3s + buffer).
|
|
132
|
+
const PANEL_TRANSITION_MS = 350;
|
|
133
|
+
|
|
66
134
|
if (megamenu || navbar) {
|
|
67
135
|
const classes = classNames(className, 'navbar-collapse', {
|
|
68
|
-
expanded:
|
|
136
|
+
expanded: isExpanded
|
|
69
137
|
});
|
|
70
|
-
const style = { display: isOpen ? 'block' : 'none' };
|
|
71
138
|
const overlayClasses = classNames('overlay', {
|
|
72
|
-
fade:
|
|
73
|
-
show:
|
|
139
|
+
fade: isVisible,
|
|
140
|
+
show: isExpanded
|
|
74
141
|
});
|
|
142
|
+
const displayStyle = { display: isVisible ? 'block' : 'none' };
|
|
75
143
|
return (
|
|
76
144
|
<CollapseBase
|
|
77
145
|
className={classes}
|
|
78
146
|
cssModule={newCssModule}
|
|
79
147
|
navbar={navbar}
|
|
80
|
-
style={
|
|
148
|
+
style={displayStyle}
|
|
149
|
+
tabIndex={-1}
|
|
150
|
+
innerRef={panelRef}
|
|
151
|
+
role={isOpen ? 'dialog' : undefined}
|
|
152
|
+
aria-modal={isOpen ? true : undefined}
|
|
153
|
+
aria-label={isOpen ? 'Menu di navigazione' : undefined}
|
|
81
154
|
data-testid={testId}
|
|
82
155
|
{...attributes}
|
|
83
156
|
>
|
|
84
|
-
<div className={overlayClasses} style={
|
|
157
|
+
<div className={overlayClasses} style={displayStyle} onClick={onOverlayClick}></div>
|
|
85
158
|
<div className='close-div'>
|
|
86
159
|
<button className='btn close-menu' type='button' onClick={onOverlayClick}>
|
|
87
160
|
<span className='visually-hidden'>{closeSrText}</span>
|
package/src/Input/Input.tsx
CHANGED
|
@@ -5,7 +5,6 @@ import React, {
|
|
|
5
5
|
ReactNode,
|
|
6
6
|
Ref,
|
|
7
7
|
useCallback,
|
|
8
|
-
useEffect,
|
|
9
8
|
useRef,
|
|
10
9
|
useState
|
|
11
10
|
} from 'react';
|
|
@@ -13,7 +12,7 @@ import React, {
|
|
|
13
12
|
import classNames from 'classnames';
|
|
14
13
|
import type { CSSModule } from 'reactstrap/types/lib/utils';
|
|
15
14
|
import { Icon } from '../Icon/Icon';
|
|
16
|
-
import { notifyDeprecation } from '../utils';
|
|
15
|
+
import { mergeAriaDescribedBy, notifyDeprecation } from '../utils';
|
|
17
16
|
import { InputContainer } from './InputContainer';
|
|
18
17
|
import { getClasses, getFormControlClass, getTag, getValidationTextControlClass, useFocus } from './utils';
|
|
19
18
|
|
|
@@ -152,19 +151,7 @@ export const Input = ({
|
|
|
152
151
|
toggleIcon(!hasIcon);
|
|
153
152
|
}, [hasIcon, isHidden]);
|
|
154
153
|
|
|
155
|
-
const divResizeRef = useRef<HTMLDivElement>(null);
|
|
156
154
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
157
|
-
const [width, setWidth] = useState('100');
|
|
158
|
-
|
|
159
|
-
useEffect(() => {
|
|
160
|
-
if (divResizeRef.current != null && divResizeRef.current.classList.contains('input-number-adaptive')) {
|
|
161
|
-
if (!value) {
|
|
162
|
-
setWidth(`calc(70px)`);
|
|
163
|
-
} else {
|
|
164
|
-
setWidth(`calc(70px + ${`${value}`.length}ch)`);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}, [value]);
|
|
168
155
|
|
|
169
156
|
// eslint-disable-next-line prefer-const
|
|
170
157
|
let { bsSize, valid, ...rest } = attributes;
|
|
@@ -185,6 +172,7 @@ export const Input = ({
|
|
|
185
172
|
type?: InputType;
|
|
186
173
|
size?: number;
|
|
187
174
|
['aria-describedby']?: string;
|
|
175
|
+
['aria-invalid']?: true;
|
|
188
176
|
} = {};
|
|
189
177
|
if (size && !isNumber(size)) {
|
|
190
178
|
notifyDeprecation('Please use the prop "bsSize" instead of the "size" to bootstrap\'s input sizing.');
|
|
@@ -197,11 +185,8 @@ export const Input = ({
|
|
|
197
185
|
extraAttributes.type = type;
|
|
198
186
|
}
|
|
199
187
|
|
|
200
|
-
//
|
|
188
|
+
// Associate the input field with the help text and, when present, the error message.
|
|
201
189
|
const infoId = id && infoText ? `${id}Description` : undefined;
|
|
202
|
-
if (infoId) {
|
|
203
|
-
extraAttributes['aria-describedby'] = infoId;
|
|
204
|
-
}
|
|
205
190
|
|
|
206
191
|
if (
|
|
207
192
|
attributes.children &&
|
|
@@ -216,6 +201,20 @@ export const Input = ({
|
|
|
216
201
|
const inputPassword = extraAttributes.type === 'password';
|
|
217
202
|
|
|
218
203
|
const indeterminateCheckboxInput = type === 'checkbox' && className?.includes('semi-checked');
|
|
204
|
+
const rendersContainer =
|
|
205
|
+
!noWrapper &&
|
|
206
|
+
!indeterminateCheckboxInput &&
|
|
207
|
+
(['currency', 'percentage', 'adaptive', 'number'].includes(type) ||
|
|
208
|
+
Boolean(placeholder || inputPassword || normalized || label || validationText));
|
|
209
|
+
const errorId = id && valid === false && rendersContainer ? `${id}-error` : undefined;
|
|
210
|
+
const describedBy = mergeAriaDescribedBy(rest['aria-describedby'], infoId, errorId);
|
|
211
|
+
|
|
212
|
+
if (describedBy) {
|
|
213
|
+
extraAttributes['aria-describedby'] = describedBy;
|
|
214
|
+
}
|
|
215
|
+
if (valid === false) {
|
|
216
|
+
extraAttributes['aria-invalid'] = true;
|
|
217
|
+
}
|
|
219
218
|
|
|
220
219
|
// Styling
|
|
221
220
|
const { activeClass, extraLabelClass, validationTextClass, inputClasses, wrapperClass } = getClasses(
|
|
@@ -257,6 +256,7 @@ export const Input = ({
|
|
|
257
256
|
label,
|
|
258
257
|
validationTextClass,
|
|
259
258
|
validationText,
|
|
259
|
+
errorId,
|
|
260
260
|
wrapperClass,
|
|
261
261
|
hasButtonRight,
|
|
262
262
|
buttonRight,
|
|
@@ -312,8 +312,7 @@ export const Input = ({
|
|
|
312
312
|
disabled: rest.disabled,
|
|
313
313
|
'input-number-adaptive': type === 'adaptive'
|
|
314
314
|
})}
|
|
315
|
-
style={{ width }}
|
|
316
|
-
ref={divResizeRef}
|
|
315
|
+
style={type === 'adaptive' ? { width: !value ? '70px' : `min(calc(70px + ${`${value}`.length}ch), 100%)` } : undefined}
|
|
317
316
|
>
|
|
318
317
|
{['currency', 'percentage'].includes(type) && (
|
|
319
318
|
<span className='input-group-text fw-semibold'>{addonText}</span>
|
|
@@ -7,6 +7,7 @@ export interface InputContainerProps extends HTMLAttributes<HTMLElement> {
|
|
|
7
7
|
validationTextClass: string;
|
|
8
8
|
label: string | ReactNode | undefined;
|
|
9
9
|
validationText: string | undefined;
|
|
10
|
+
errorId?: string;
|
|
10
11
|
id: string | undefined;
|
|
11
12
|
infoId: string | undefined;
|
|
12
13
|
infoText: string | undefined;
|
|
@@ -31,6 +32,7 @@ export const InputContainer: FC<InputContainerProps> = ({
|
|
|
31
32
|
label,
|
|
32
33
|
validationTextClass,
|
|
33
34
|
validationText,
|
|
35
|
+
errorId,
|
|
34
36
|
wrapperClass,
|
|
35
37
|
hasButtonRight,
|
|
36
38
|
buttonRight,
|
|
@@ -52,7 +54,9 @@ export const InputContainer: FC<InputContainerProps> = ({
|
|
|
52
54
|
{infoText}
|
|
53
55
|
</small>
|
|
54
56
|
)}
|
|
55
|
-
<div className={validationTextClass}>
|
|
57
|
+
<div id={errorId} className={validationTextClass}>
|
|
58
|
+
{validationText}
|
|
59
|
+
</div>
|
|
56
60
|
{hasButtonRight && <div className='input-group-append'>{buttonRight}</div>}
|
|
57
61
|
</div>
|
|
58
62
|
</div>
|
|
@@ -69,7 +73,9 @@ export const InputContainer: FC<InputContainerProps> = ({
|
|
|
69
73
|
{infoText}
|
|
70
74
|
</small>
|
|
71
75
|
)}
|
|
72
|
-
<div className={validationTextClass}>
|
|
76
|
+
<div id={errorId} className={validationTextClass}>
|
|
77
|
+
{validationText}
|
|
78
|
+
</div>
|
|
73
79
|
</div>
|
|
74
80
|
);
|
|
75
81
|
};
|
package/src/Input/TextArea.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { ReactNode, Ref, TextareaHTMLAttributes } from 'react';
|
|
2
2
|
|
|
3
3
|
import type { CSSModule } from 'reactstrap/types/lib/utils';
|
|
4
|
+
import { mergeAriaDescribedBy } from '../utils';
|
|
4
5
|
import { InputContainer } from './InputContainer';
|
|
5
6
|
import { getClasses, getFormControlClass, getValidationTextControlClass, useFocus } from './utils';
|
|
6
7
|
|
|
@@ -54,14 +55,20 @@ export const TextArea = ({
|
|
|
54
55
|
|
|
55
56
|
const validationTextControlClass = getValidationTextControlClass({ valid }, cssModule);
|
|
56
57
|
|
|
57
|
-
const extraAttributes: { ['aria-describedby']?: string } = {};
|
|
58
|
+
const extraAttributes: { ['aria-describedby']?: string; ['aria-invalid']?: true } = {};
|
|
58
59
|
|
|
59
60
|
//Chiamo questa funzione per impostare classNames a 'form-control'
|
|
60
61
|
const formControlClass = getFormControlClass({}, cssModule);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const rendersContainer = Boolean(placeholder || normalized || label || validationText);
|
|
63
|
+
// Associate the input field with the help text and, when present, the error message.
|
|
64
|
+
const infoId = id && infoText ? `${id}Description` : undefined;
|
|
65
|
+
const errorId = id && valid === false && rendersContainer ? `${id}-error` : undefined;
|
|
66
|
+
const describedBy = mergeAriaDescribedBy(attributes['aria-describedby'], infoId, errorId);
|
|
67
|
+
if (describedBy) {
|
|
68
|
+
extraAttributes['aria-describedby'] = describedBy;
|
|
69
|
+
}
|
|
70
|
+
if (valid === false) {
|
|
71
|
+
extraAttributes['aria-invalid'] = true;
|
|
65
72
|
}
|
|
66
73
|
|
|
67
74
|
// Styling
|
|
@@ -102,6 +109,7 @@ export const TextArea = ({
|
|
|
102
109
|
label,
|
|
103
110
|
validationTextClass,
|
|
104
111
|
validationText,
|
|
112
|
+
errorId,
|
|
105
113
|
wrapperClass
|
|
106
114
|
};
|
|
107
115
|
|
package/src/utils.tsx
CHANGED
|
@@ -40,6 +40,17 @@ export function mapToCssModules(className: string | null, cssModules?: Record<st
|
|
|
40
40
|
.join(' ');
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Combines ID reference lists for `aria-describedby` without losing a
|
|
45
|
+
* description that was already supplied by the consumer.
|
|
46
|
+
*/
|
|
47
|
+
export function mergeAriaDescribedBy(...descriptions: Array<string | undefined | null>) {
|
|
48
|
+
const ids = descriptions.flatMap((description) => description?.trim().split(/\s+/) ?? []);
|
|
49
|
+
const uniqueIds = [...new Set(ids.filter(Boolean))];
|
|
50
|
+
|
|
51
|
+
return uniqueIds.length > 0 ? uniqueIds.join(' ') : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
type UnknownObject = Record<string, unknown>;
|
|
44
55
|
|
|
45
56
|
export function pick<T extends UnknownObject>(obj: T, keys: keyof T | Array<keyof T>): Partial<T> {
|