@molecule/app-rating-form-react 3.0.0 → 4.0.1

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/README.md CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-10-27T23:36:37.698Z
6
+ Generated: 2026-11-12T04:41:22.161Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-rating-form-react
@@ -103,9 +103,9 @@ function RatingForm({
103
103
 
104
104
  Peer dependencies:
105
105
 
106
- - `@molecule/app-react` ^3.0.0
106
+ - `@molecule/app-react` ^4.0.0
107
107
  - `@molecule/app-ui` ^1.0.1
108
- - `@molecule/app-ui-react` ^3.0.0
108
+ - `@molecule/app-ui-react` ^4.0.0
109
109
  - `react` ^18.0.0 || ^19.0.0
110
110
 
111
111
  ### Runtime Dependencies
@@ -1 +1 @@
1
- {"version":3,"file":"RatingForm.d.ts","sourceRoot":"","sources":["../src/RatingForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAOtD,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACnE,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,qCAAqC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,wDAAwD;IACxD,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,oBAAoB;IACpB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,2BAA2B;I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x as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState } from 'react';
2
+ import { useRef, useState } from 'react';
3
3
  import { useTranslation } from '@molecule/app-react';
4
4
  import { getClassMap } from '@molecule/app-ui';
5
5
  import { Button, Textarea } from '@molecule/app-ui-react';
@@ -16,6 +16,12 @@ export function RatingForm({ onSubmit, max = 5, defaultRating = 0, requireCommen
16
16
  const [comment, setComment] = useState('');
17
17
  const [submitting, setSubmitting] = useState(false);
18
18
  const display = hover || rating;
19
+ // The star holding the group's one tab stop: the selected one, or the first
20
+ // when no star is selected — no rating yet, or a defaultRating outside
21
+ // 1..max, which marks no star (an out-of-range value must still leave the
22
+ // group reachable from the keyboard).
23
+ const tabStop = rating >= 1 && rating <= max ? rating : 1;
24
+ const starRefs = useRef(new Map());
19
25
  /**
20
26
  * Handles form submission: validates state, delegates to onSubmit, and manages submitting flag.
21
27
  * @param e - The form submit event.
@@ -34,7 +40,53 @@ export function RatingForm({ onSubmit, max = 5, defaultRating = 0, requireCommen
34
40
  setSubmitting(false);
35
41
  }
36
42
  }
37
- return (_jsxs("form", { onSubmit: handle, className: cm.cn(cm.stack(3), className), children: [title && _jsx("h3", { className: cm.cn(cm.textSize('base'), cm.fontWeight('semibold')), children: title }), _jsx("div", { role: "radiogroup", "aria-label": t('rating.label', {}, { defaultValue: 'Rating' }), className: cm.flex({ align: 'center', gap: 'xs' }), onMouseLeave: () => setHover(0), children: Array.from({ length: max }, (_, i) => i + 1).map((n) => (_jsx("button", { type: "button", role: "radio", "data-mol-id": "rating-form-star", "aria-checked": rating === n, "aria-label": t('rating.star', { n, max }, { defaultValue: '{{n}} of {{max}}' }), onClick: () => setRating(n), onMouseEnter: () => setHover(n),
43
+ /**
44
+ * Selects a star and moves focus with it — the APG radio group's roving
45
+ * tabindex, where the checked star is the group's one keyboard stop.
46
+ * @param n - The star to select.
47
+ */
48
+ function selectAndFocus(n) {
49
+ setRating(n);
50
+ starRefs.current.get(n)?.focus();
51
+ }
52
+ /**
53
+ * Handles the radio keys on a star (the APG radio group pattern): ArrowRight /
54
+ * ArrowDown select and focus the next star, ArrowLeft / ArrowUp the previous
55
+ * one, both wrapping; Home and End jump to the first and last. The handled
56
+ * keys are prevented (they would otherwise scroll or move focus); Space and
57
+ * Enter stay the native button click, and any other key is ignored.
58
+ * @param e - The key event on a star button.
59
+ */
60
+ function onStarKeyDown(e) {
61
+ const current = tabStop;
62
+ let next;
63
+ switch (e.key) {
64
+ case 'ArrowRight':
65
+ case 'ArrowDown':
66
+ next = current >= max ? 1 : current + 1;
67
+ break;
68
+ case 'ArrowLeft':
69
+ case 'ArrowUp':
70
+ next = current <= 1 ? max : current - 1;
71
+ break;
72
+ case 'Home':
73
+ next = 1;
74
+ break;
75
+ case 'End':
76
+ next = max;
77
+ break;
78
+ default:
79
+ return;
80
+ }
81
+ e.preventDefault();
82
+ selectAndFocus(next);
83
+ }
84
+ return (_jsxs("form", { onSubmit: handle, className: cm.cn(cm.stack(3), className), children: [title && _jsx("h3", { className: cm.cn(cm.textSize('base'), cm.fontWeight('semibold')), children: title }), _jsx("div", { role: "radiogroup", tabIndex: -1, "aria-label": t('rating.label', {}, { defaultValue: 'Rating' }), className: cm.flex({ align: 'center', gap: 'xs' }), onMouseLeave: () => setHover(0), children: Array.from({ length: max }, (_, i) => i + 1).map((n) => (_jsx("button", { ref: (el) => {
85
+ if (el)
86
+ starRefs.current.set(n, el);
87
+ else
88
+ starRefs.current.delete(n);
89
+ }, type: "button", role: "radio", "data-mol-id": "rating-form-star", tabIndex: n === tabStop ? 0 : -1, "aria-checked": rating === n, "aria-label": t('rating.star', { n, max }, { defaultValue: '{{n}} of {{max}}' }), onClick: () => setRating(n), onKeyDown: onStarKeyDown, onMouseEnter: () => setHover(n),
38
90
  /* mol-bespoke-button: icon-only 28px star glyph, no label and no
39
91
  button surface — the star IS the control, so the inline
40
92
  background/border are native resets. Fill colour is a theme
@@ -49,7 +101,7 @@ export function RatingForm({ onSubmit, max = 5, defaultRating = 0, requireCommen
49
101
  ? 'var(--mol-color-warning, #facc15)'
50
102
  : 'var(--mol-color-border, rgba(128,128,128,0.4))',
51
103
  }, children: "\u2605" }, n))) }), _jsx(Textarea, { value: comment, onChange: (e) => setComment(e.target.value), placeholder: commentPlaceholder ??
52
- t('rating.commentPlaceholder', {}, { defaultValue: 'Share your thoughts (optional)' }), rows: 4, "aria-label": "Comment" }), _jsx(Button, { type: "submit", variant: "solid", color: "primary", disabled: submitting || !rating, children: submitting
104
+ t('rating.commentPlaceholder', {}, { defaultValue: 'Share your thoughts (optional)' }), rows: 4, "aria-label": t('rating.comment', {}, { defaultValue: 'Comment' }) }), _jsx(Button, { type: "submit", variant: "solid", color: "primary", disabled: submitting || !rating, children: submitting
53
105
  ? t('rating.submitting', {}, { defaultValue: 'Submitting…' })
54
106
  : (submitLabel ?? t('rating.submit', {}, { defaultValue: 'Submit review' })) })] }));
55
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-rating-form-react",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Interactive star rating + textarea + submit form for collecting reviews",
5
5
  "homepage": "https://www.molecule.dev/packages/app-rating-form-react",
6
6
  "type": "module",
@@ -33,15 +33,15 @@
33
33
  "directory": "packages/app/features/rating-form-react"
34
34
  },
35
35
  "peerDependencies": {
36
- "@molecule/app-react": "^3.0.0",
36
+ "@molecule/app-react": "^4.0.0",
37
37
  "@molecule/app-ui": "^1.0.1",
38
- "@molecule/app-ui-react": "^3.0.0",
38
+ "@molecule/app-ui-react": "^4.0.0",
39
39
  "react": "^18.0.0 || ^19.0.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@molecule/app-react": "3.0.0",
43
- "@molecule/app-ui": "1.3.8",
44
- "@molecule/app-ui-react": "3.0.0",
42
+ "@molecule/app-react": "4.10.1",
43
+ "@molecule/app-ui": "1.5.0",
44
+ "@molecule/app-ui-react": "4.2.0",
45
45
  "@types/node": "26.6.5",
46
46
  "@types/react": "19.3.0",
47
47
  "@types/react-dom": "19.3.0",