@mittwald/flow-react-components 1.6.4 → 1.6.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.
@@ -35,11 +35,22 @@ var useRegisterSectionHeading = (id) => {
35
35
  /**
36
36
  * The `aria-labelledby` of a grid or table: its own label, else the heading of
37
37
  * the surrounding `Section` once that heading renders.
38
+ *
39
+ * A heading mounting in the same commit registers only in its layout effect. So
40
+ * the first render assumes the heading and the layout effect below re-checks
41
+ * before paint — otherwise React Aria warns about a missing label.
38
42
  */
39
43
  var useLabelledBySectionHeading = (props) => {
40
44
  const sectionHeading = useContext(sectionHeadingContext);
41
- if (props["aria-labelledby"] || props["aria-label"]) return props["aria-labelledby"];
42
- return sectionHeading?.isRendered ? sectionHeading.id : void 0;
45
+ const [isMounted, setIsMounted] = useState(false);
46
+ const hasOwnLabel = !!(props["aria-labelledby"] || props["aria-label"]);
47
+ const needsMountCheck = !!sectionHeading && !hasOwnLabel;
48
+ useLayoutEffect(() => {
49
+ if (needsMountCheck) setIsMounted(true);
50
+ }, [needsMountCheck]);
51
+ if (hasOwnLabel) return props["aria-labelledby"];
52
+ if (!sectionHeading) return;
53
+ return sectionHeading.isRendered || !isMounted ? sectionHeading.id : void 0;
43
54
  };
44
55
  export { SectionHeadingProvider, SectionHeadingReset, useLabelledBySectionHeading, useRegisterSectionHeading, useSectionHeading };
45
56
 
@@ -1 +1 @@
1
- {"version":3,"file":"context.mjs","names":[],"sources":["../../../../../../../src/components/Section/context.ts"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport {\n createContext,\n createElement,\n useCallback,\n useContext,\n useLayoutEffect,\n useMemo,\n useState,\n} from \"react\";\n\ninterface SectionHeading {\n /** The id the surrounding `Section` gives its heading. */\n id: string;\n /** Whether a heading currently renders with that id. */\n isRendered: boolean;\n /** Called by a heading that renders with the id; returns the cleanup. */\n register: () => () => void;\n}\n\nconst sectionHeadingContext = createContext<SectionHeading | undefined>(\n undefined,\n);\n\n/** The heading state a `Section` provides for the given heading id. */\nexport const useSectionHeading = (id: string): SectionHeading => {\n const [renderedCount, setRenderedCount] = useState(0);\n\n const register = useCallback(() => {\n setRenderedCount((count) => count + 1);\n return () => setRenderedCount((count) => count - 1);\n }, []);\n\n return useMemo(\n () => ({ id, isRendered: renderedCount > 0, register }),\n [id, renderedCount, register],\n );\n};\n\nexport const SectionHeadingProvider = sectionHeadingContext.Provider;\n\n/**\n * Ends the surrounding `Section`'s heading scope, for content that has a\n * heading of its own (`Accordion`, `Alert`, an overlay, …).\n */\nexport const SectionHeadingReset: FC<PropsWithChildren> = ({ children }) =>\n createElement(sectionHeadingContext.Provider, { value: undefined }, children);\n\n/** Marks the section heading as rendered while a heading carries its id. */\nexport const useRegisterSectionHeading = (id: string | undefined) => {\n const sectionHeading = useContext(sectionHeadingContext);\n const register =\n sectionHeading && id === sectionHeading.id\n ? sectionHeading.register\n : undefined;\n\n useLayoutEffect(() => register?.(), [register]);\n};\n\n/**\n * The `aria-labelledby` of a grid or table: its own label, else the heading of\n * the surrounding `Section` once that heading renders.\n */\nexport const useLabelledBySectionHeading = (props: {\n \"aria-label\"?: string;\n \"aria-labelledby\"?: string;\n}): string | undefined => {\n const sectionHeading = useContext(sectionHeadingContext);\n\n if (props[\"aria-labelledby\"] || props[\"aria-label\"]) {\n return props[\"aria-labelledby\"];\n }\n\n return sectionHeading?.isRendered ? sectionHeading.id : undefined;\n};\n"],"mappings":";;;;AAoBA,IAAM,wBAAwB,cAC5B,KAAA,CACF;;AAGA,IAAa,qBAAqB,OAA+B;CAC/D,MAAM,CAAC,eAAe,oBAAoB,SAAS,CAAC;CAEpD,MAAM,WAAW,kBAAkB;EACjC,kBAAkB,UAAU,QAAQ,CAAC;EACrC,aAAa,kBAAkB,UAAU,QAAQ,CAAC;CACpD,GAAG,CAAC,CAAC;CAEL,OAAO,eACE;EAAE;EAAI,YAAY,gBAAgB;EAAG;CAAS,IACrD;EAAC;EAAI;EAAe;CAAQ,CAC9B;AACF;AAEA,IAAa,yBAAyB,sBAAsB;;;;;AAM5D,IAAa,uBAA8C,EAAE,eAC3D,cAAc,sBAAsB,UAAU,EAAE,OAAO,KAAA,EAAU,GAAG,QAAQ;;AAG9E,IAAa,6BAA6B,OAA2B;CACnE,MAAM,iBAAiB,WAAW,qBAAqB;CACvD,MAAM,WACJ,kBAAkB,OAAO,eAAe,KACpC,eAAe,WACf,KAAA;CAEN,sBAAsB,WAAW,GAAG,CAAC,QAAQ,CAAC;AAChD;;;;;AAMA,IAAa,+BAA+B,UAGlB;CACxB,MAAM,iBAAiB,WAAW,qBAAqB;CAEvD,IAAI,MAAM,sBAAsB,MAAM,eACpC,OAAO,MAAM;CAGf,OAAO,gBAAgB,aAAa,eAAe,KAAK,KAAA;AAC1D"}
1
+ {"version":3,"file":"context.mjs","names":[],"sources":["../../../../../../../src/components/Section/context.ts"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport {\n createContext,\n createElement,\n useCallback,\n useContext,\n useLayoutEffect,\n useMemo,\n useState,\n} from \"react\";\n\ninterface SectionHeading {\n /** The id the surrounding `Section` gives its heading. */\n id: string;\n /** Whether a heading currently renders with that id. */\n isRendered: boolean;\n /** Called by a heading that renders with the id; returns the cleanup. */\n register: () => () => void;\n}\n\nconst sectionHeadingContext = createContext<SectionHeading | undefined>(\n undefined,\n);\n\n/** The heading state a `Section` provides for the given heading id. */\nexport const useSectionHeading = (id: string): SectionHeading => {\n const [renderedCount, setRenderedCount] = useState(0);\n\n const register = useCallback(() => {\n setRenderedCount((count) => count + 1);\n return () => setRenderedCount((count) => count - 1);\n }, []);\n\n return useMemo(\n () => ({ id, isRendered: renderedCount > 0, register }),\n [id, renderedCount, register],\n );\n};\n\nexport const SectionHeadingProvider = sectionHeadingContext.Provider;\n\n/**\n * Ends the surrounding `Section`'s heading scope, for content that has a\n * heading of its own (`Accordion`, `Alert`, an overlay, …).\n */\nexport const SectionHeadingReset: FC<PropsWithChildren> = ({ children }) =>\n createElement(sectionHeadingContext.Provider, { value: undefined }, children);\n\n/** Marks the section heading as rendered while a heading carries its id. */\nexport const useRegisterSectionHeading = (id: string | undefined) => {\n const sectionHeading = useContext(sectionHeadingContext);\n const register =\n sectionHeading && id === sectionHeading.id\n ? sectionHeading.register\n : undefined;\n\n useLayoutEffect(() => register?.(), [register]);\n};\n\n/**\n * The `aria-labelledby` of a grid or table: its own label, else the heading of\n * the surrounding `Section` once that heading renders.\n *\n * A heading mounting in the same commit registers only in its layout effect. So\n * the first render assumes the heading and the layout effect below re-checks\n * before paint — otherwise React Aria warns about a missing label.\n */\nexport const useLabelledBySectionHeading = (props: {\n \"aria-label\"?: string;\n \"aria-labelledby\"?: string;\n}): string | undefined => {\n const sectionHeading = useContext(sectionHeadingContext);\n const [isMounted, setIsMounted] = useState(false);\n\n const hasOwnLabel = !!(props[\"aria-labelledby\"] || props[\"aria-label\"]);\n const needsMountCheck = !!sectionHeading && !hasOwnLabel;\n\n useLayoutEffect(() => {\n if (needsMountCheck) {\n setIsMounted(true);\n }\n }, [needsMountCheck]);\n\n if (hasOwnLabel) {\n return props[\"aria-labelledby\"];\n }\n\n if (!sectionHeading) {\n return undefined;\n }\n\n return sectionHeading.isRendered || !isMounted\n ? sectionHeading.id\n : undefined;\n};\n"],"mappings":";;;;AAoBA,IAAM,wBAAwB,cAC5B,KAAA,CACF;;AAGA,IAAa,qBAAqB,OAA+B;CAC/D,MAAM,CAAC,eAAe,oBAAoB,SAAS,CAAC;CAEpD,MAAM,WAAW,kBAAkB;EACjC,kBAAkB,UAAU,QAAQ,CAAC;EACrC,aAAa,kBAAkB,UAAU,QAAQ,CAAC;CACpD,GAAG,CAAC,CAAC;CAEL,OAAO,eACE;EAAE;EAAI,YAAY,gBAAgB;EAAG;CAAS,IACrD;EAAC;EAAI;EAAe;CAAQ,CAC9B;AACF;AAEA,IAAa,yBAAyB,sBAAsB;;;;;AAM5D,IAAa,uBAA8C,EAAE,eAC3D,cAAc,sBAAsB,UAAU,EAAE,OAAO,KAAA,EAAU,GAAG,QAAQ;;AAG9E,IAAa,6BAA6B,OAA2B;CACnE,MAAM,iBAAiB,WAAW,qBAAqB;CACvD,MAAM,WACJ,kBAAkB,OAAO,eAAe,KACpC,eAAe,WACf,KAAA;CAEN,sBAAsB,WAAW,GAAG,CAAC,QAAQ,CAAC;AAChD;;;;;;;;;AAUA,IAAa,+BAA+B,UAGlB;CACxB,MAAM,iBAAiB,WAAW,qBAAqB;CACvD,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAEhD,MAAM,cAAc,CAAC,EAAE,MAAM,sBAAsB,MAAM;CACzD,MAAM,kBAAkB,CAAC,CAAC,kBAAkB,CAAC;CAE7C,sBAAsB;EACpB,IAAI,iBACF,aAAa,IAAI;CAErB,GAAG,CAAC,eAAe,CAAC;CAEpB,IAAI,aACF,OAAO,MAAM;CAGf,IAAI,CAAC,gBACH;CAGF,OAAO,eAAe,cAAc,CAAC,YACjC,eAAe,KACf,KAAA;AACN"}
@@ -20,6 +20,10 @@ export declare const useRegisterSectionHeading: (id: string | undefined) => void
20
20
  /**
21
21
  * The `aria-labelledby` of a grid or table: its own label, else the heading of
22
22
  * the surrounding `Section` once that heading renders.
23
+ *
24
+ * A heading mounting in the same commit registers only in its layout effect. So
25
+ * the first render assumes the heading and the layout effect below re-checks
26
+ * before paint — otherwise React Aria warns about a missing label.
23
27
  */
24
28
  export declare const useLabelledBySectionHeading: (props: {
25
29
  "aria-label"?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/flow-react-components",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "type": "module",
5
5
  "description": "A React implementation of Flow, mittwald’s design system",
6
6
  "homepage": "https://flow.mittwald.de",
@@ -84,9 +84,9 @@
84
84
  "@internationalized/string-compiler": "^3.4.1",
85
85
  "@lezer/common": "^1.5.2",
86
86
  "@lezer/highlight": "^1.2.3",
87
- "@mittwald/flow-icons": "^1.6.4",
87
+ "@mittwald/flow-icons": "^1.6.5",
88
88
  "@mittwald/password-tools-js": "^3.0.0",
89
- "@mittwald/react-tunnel": "^1.6.4",
89
+ "@mittwald/react-tunnel": "^1.6.5",
90
90
  "@mittwald/react-use-promise": "^4.2.2",
91
91
  "@react-aria/form": "^3.2.1",
92
92
  "@react-aria/i18n": "^3.13.1",
@@ -139,13 +139,13 @@
139
139
  "@internationalized/date": "^3.12.3",
140
140
  "@lezer/generator": "^1.8.0",
141
141
  "@lezer/lr": "^1.4.10",
142
- "@mittwald/flow-components-base": "1.6.4",
143
- "@mittwald/flow-core": "1.6.4",
144
- "@mittwald/flow-design-tokens": "1.6.4",
145
- "@mittwald/flow-icons-base": "1.6.4",
142
+ "@mittwald/flow-components-base": "1.6.5",
143
+ "@mittwald/flow-core": "1.6.5",
144
+ "@mittwald/flow-design-tokens": "1.6.5",
145
+ "@mittwald/flow-icons-base": "1.6.5",
146
146
  "@mittwald/react-use-promise": "^4.2.2",
147
147
  "@mittwald/remote-dom-react": "1.2.2-mittwald.10",
148
- "@mittwald/typescript-config": "1.6.4",
148
+ "@mittwald/typescript-config": "1.6.5",
149
149
  "@nx/storybook": "^22.7.6",
150
150
  "@storybook/addon-a11y": "^10.5.10",
151
151
  "@storybook/addon-actions": "^9.0.8",
@@ -199,7 +199,7 @@
199
199
  },
200
200
  "peerDependencies": {
201
201
  "@internationalized/date": "^3.12.2",
202
- "@mittwald/flow-icons-pro": "1.6.4",
202
+ "@mittwald/flow-icons-pro": "1.6.5",
203
203
  "@mittwald/react-use-promise": "^4.2.2",
204
204
  "next": "^16.2.3",
205
205
  "react": "^19.2.0",
@@ -223,5 +223,5 @@
223
223
  "browserslist": [
224
224
  "baseline widely available"
225
225
  ],
226
- "gitHead": "85d1c1e3f832eb86a078a40e3cbbac2fe760b2bb"
226
+ "gitHead": "50bc647c2cc3d18855186203720d34bd549299ed"
227
227
  }