Skip to content

feat: add new mui formik color picker component#231

Open
tomrndom wants to merge 6 commits intomainfrom
feature/mui-formik-color-picker
Open

feat: add new mui formik color picker component#231
tomrndom wants to merge 6 commits intomainfrom
feature/mui-formik-color-picker

Conversation

@tomrndom
Copy link
Copy Markdown
Contributor

@tomrndom tomrndom commented Apr 30, 2026

  • fix: add prop to fetch only initial options on async-select
image

ref: https://app.clickup.com/t/86b9n7p5w

Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com

Summary by CodeRabbit

  • New Features
    • Async select now supports an optional local filtering mode: switches from debounced remote lookups to client-side, case-insensitive filtering of existing options to reduce network calls and improve responsiveness.
    • Added a Formik-connected color input component: local edit state, commit-on-blur behavior, validation display, and a styled color swatch for consistent form use.

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@tomrndom has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 4 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9185db9b-34d4-4d83-8118-6e24ad4f92de

📥 Commits

Reviewing files that changed from the base of the PR and between ae683f6 and 5241fff.

📒 Files selected for processing (2)
  • src/components/mui/formik-inputs/mui-formik-color-input.js
  • src/utils/constants.js
📝 Walkthrough

Walkthrough

Adds a client-side filtering mode to MuiFormikAsyncAutocomplete, and introduces a new Formik-connected color input component MuiFormikColorInput with exports and a webpack entry.

Changes

Async Select: localFilter mode

Layer / File(s) Summary
API / Props
src/components/mui/formik-inputs/mui-formik-async-select.js
Adds localFilter prop (default false) to component signature and documents mode.
Behavior / Effects
src/components/mui/formik-inputs/mui-formik-async-select.js
Debounced remote fetch effect is gated: it runs only when localFilter is falsy and searchTerm is present.
Wiring / Autocomplete
src/components/mui/formik-inputs/mui-formik-async-select.js
onInputChange is enabled only for remote mode; when localFilter is true, filterOptions is supplied to do case-insensitive substring filtering on option.label.
Runtime Validation
src/components/mui/formik-inputs/mui-formik-async-select.js
Adds MuiFormikAsyncAutocomplete.propTypes including localFilter: PropTypes.bool.

Color Input component + exports / build entry

Layer / File(s) Summary
Component Implementation
src/components/mui/formik-inputs/mui-formik-color-input.js
Adds MuiFormikColorInput that uses useField(name), keeps a localValue defaulting to #000000, updates local state on change, marks touched on blur, and writes back to Formik only when dirty. Renders an MUI TextField with type="color" and validation UI.
PropTypes / Export
src/components/mui/formik-inputs/mui-formik-color-input.js
Adds propTypes requiring name and exports component as default.
Public Exports
src/components/index.js
Exports MuiFormikColorInput from ./mui/formik-inputs/mui-formik-color-input.
Build Entry
webpack.common.js
Adds webpack entry components/mui/formik-inputs/color-input./src/components/mui/formik-inputs/mui-formik-color-input.js.

Sequence Diagram

sequenceDiagram
  participant User as User
  participant Component as MuiFormikAsyncAutocomplete
  participant API as Remote API
  Note over Component: Mode = localFilter ? local : remote

  User->>Component: Type input
  alt localFilter == true
    Component->>Component: filterOptions(options, input) (case-insensitive substring)
    Component-->>User: show filtered options
  else remote mode
    Component->>Component: debounce input -> set searchTerm
    Component->>API: fetchOptions(searchTerm)
    API-->>Component: return options
    Component-->>User: show fetched options
  end
  User->>Component: Select option
  Component-->>User: emit selection / update Formik
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • smarcet
  • santipalenque

Poem

🐰 I hopped in with a tiny brush of light,
A color picker snug and tidy, bright,
The async select learned to quietly sift,
Local matches bloom — remote calls take a lift,
Happy forms hop on, all snug tonight. 🎨✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new Material-UI Formik color picker component, which aligns with the primary feature in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/mui-formik-color-picker

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/mui/formik-inputs/mui-formik-async-select.js`:
- Around line 34-35: The component defines and accepts isMulti but still uses
the older multiple flag when computing Autocomplete value and onChange, causing
Formik to store the wrong shape; update all selection/value logic to
consistently use isMulti (not multiple) — pass isMulti to the MUI Autocomplete
prop, branch on isMulti when deriving value from Formik field and when calling
setFieldValue (map arrays for multi-select, single item otherwise), and
remove/rename any references to multiple so Formik and Autocomplete agree on the
value shape (check functions/variables around isMulti, Autocomplete usage, and
the onChange/value handlers).
- Around line 107-110: The local filtering callback currently calls
opt.label.toLowerCase() which will throw if opt.label is
null/undefined/non-string; update the filter used in options.filter((opt) =>
...) to coerce or guard the label and inputValue (e.g., use String(opt.label ??
'') or (opt.label || '').toString()) and similarly normalize inputValue before
calling toLowerCase(), then perform the includes check; ensure you update the
inline filter expression where options.filter is defined to be null-safe for
labels.

In `@src/components/mui/formik-inputs/mui-formik-color-input.js`:
- Line 8: The localValue state initialized with useState(field.value ||
"#000000") can become stale on form resets; add an effect that listens for
changes to field.value (the Formik value) and calls setLocalValue(field.value ??
"#000000") to keep the color swatch in sync; locate the localValue and
setLocalValue declarations in mui-formik-color-input.js and add a useEffect
referencing field.value to update localValue when Formik reinitializes or
resets.
- Around line 20-34: The TextField currently spreads {...rest} last which allows
callers to override controlled props (type, value, onChange, onBlur) and bypass
Formik; update the component that renders TextField so you either spread
{...rest} first (before value={localValue}, onChange={handleChange},
onBlur={handleBlur}, type="color") or, preferably, strip conflicting keys from
rest (delete or omit 'type','value','onChange','onBlur') before spreading into
TextField; ensure the retained props are localValue, handleChange, handleBlur,
and the type remains "color" so Formik binding (meta.touched/meta.error) cannot
be overridden.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c5aedc0a-4634-4a6b-9aa5-2640867c3e16

📥 Commits

Reviewing files that changed from the base of the PR and between 373c59f and c31bbc0.

📒 Files selected for processing (2)
  • src/components/mui/formik-inputs/mui-formik-async-select.js
  • src/components/mui/formik-inputs/mui-formik-color-input.js

Comment on lines +34 to +35
isMulti = false,
defaultOptions
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Unify multiple control to avoid broken multi-select value handling.

Line 34 introduces isMulti, but selection/value logic still branches on multiple. This can put Autocomplete in multi mode while Formik still stores a single value.

Suggested fix
 const MuiFormikAsyncAutocomplete = ({
   name,
   queryFunction,
   multiple = false,
@@
-  queryParams = [],
-  isMulti = false,
+  queryParams = [],
   defaultOptions
 }) => {
@@
     <Autocomplete
       options={options}
       value={value}
       onChange={handleChange}
       loading={loading}
-      multiple={isMulti}
+      multiple={multiple}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/mui/formik-inputs/mui-formik-async-select.js` around lines 34
- 35, The component defines and accepts isMulti but still uses the older
multiple flag when computing Autocomplete value and onChange, causing Formik to
store the wrong shape; update all selection/value logic to consistently use
isMulti (not multiple) — pass isMulti to the MUI Autocomplete prop, branch on
isMulti when deriving value from Formik field and when calling setFieldValue
(map arrays for multi-select, single item otherwise), and remove/rename any
references to multiple so Formik and Autocomplete agree on the value shape
(check functions/variables around isMulti, Autocomplete usage, and the
onChange/value handlers).

Comment on lines +107 to +110
? (options, { inputValue }) =>
options.filter((opt) =>
opt.label.toLowerCase().includes(inputValue.toLowerCase())
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Make local filtering null-safe for option labels.

This path calls toLowerCase() directly on opt.label; a non-string/empty label will throw at runtime.

Suggested fix
           ? (options, { inputValue }) =>
             options.filter((opt) =>
-              opt.label.toLowerCase().includes(inputValue.toLowerCase())
+              (opt.label ?? "")
+                .toString()
+                .toLowerCase()
+                .includes((inputValue ?? "").toLowerCase())
             )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
? (options, { inputValue }) =>
options.filter((opt) =>
opt.label.toLowerCase().includes(inputValue.toLowerCase())
)
? (options, { inputValue }) =>
options.filter((opt) =>
(opt.label ?? "")
.toString()
.toLowerCase()
.includes((inputValue ?? "").toLowerCase())
)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/mui/formik-inputs/mui-formik-async-select.js` around lines 107
- 110, The local filtering callback currently calls opt.label.toLowerCase()
which will throw if opt.label is null/undefined/non-string; update the filter
used in options.filter((opt) => ...) to coerce or guard the label and inputValue
(e.g., use String(opt.label ?? '') or (opt.label || '').toString()) and
similarly normalize inputValue before calling toLowerCase(), then perform the
includes check; ensure you update the inline filter expression where
options.filter is defined to be null-safe for labels.

Comment thread src/components/mui/formik-inputs/mui-formik-color-input.js
Comment thread src/components/mui/formik-inputs/mui-formik-color-input.js
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom requested a review from smarcet May 4, 2026 12:57
Comment thread src/components/mui/formik-inputs/mui-formik-color-input.js Outdated
Comment thread src/components/mui/formik-inputs/mui-formik-async-select.js Outdated
Comment thread src/components/mui/formik-inputs/mui-formik-async-select.js
Comment thread src/components/mui/formik-inputs/mui-formik-async-select.js Outdated
Comment thread src/components/mui/formik-inputs/mui-formik-color-input.js Outdated
Comment thread src/components/mui/formik-inputs/mui-formik-color-input.js
Copy link
Copy Markdown
Collaborator

@smarcet smarcet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomrndom please review comments

…ments

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (2)
src/components/mui/formik-inputs/mui-formik-async-select.js (2)

115-118: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

opt.label.toLowerCase() still throws on null/undefined labels.

The filterOptions callback can crash if any option has a missing label. This was flagged in a previous review and remains unresolved.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/mui/formik-inputs/mui-formik-async-select.js` around lines 115
- 118, The filterOptions callback in mui-formik-async-select.js can throw when
an option has a null/undefined label; update the filter function used by
filterOptions (the arrow function in that file) to defensively coerce the label
to a string before calling toLowerCase (e.g., use (opt && (opt.label ?? '')) or
String(opt?.label ?? '') then toLowerCase) and also guard against opt being
falsy, so options with missing labels no longer crash the filtering logic.

42-43: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

isMulti / multiple duality persists — Autocomplete and handleChange still disagree on multi-select shape.

Line 107 passes multiple={isMulti} to Autocomplete, while handleChange (line 84) still branches on multiple. When isMulti=true but multiple=false (the default), Formik receives a single value while MUI is in multi-select mode, producing a broken experience.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/mui/formik-inputs/mui-formik-async-select.js` around lines 42
- 43, The component mixes two names for the same concept: use the single prop
name isMulti everywhere to avoid shape mismatches. Update the handleChange
function to branch on isMulti (not multiple), ensure the Autocomplete is passed
multiple={isMulti}, and remove/normalize any use of a separate multiple prop in
the component props/destructuring so Formik always receives the value shape that
matches Autocomplete's multiple={isMulti} behavior.
🧹 Nitpick comments (1)
src/components/mui/formik-inputs/mui-formik-async-select.js (1)

158-164: ⚡ Quick win

PropTypes block is incomplete — 6 of 11 props are undocumented.

The following props accepted by the component are absent from the propTypes definition: multiple, placeholder, plainValue, hiddenOptions, formatSelectedValue, and isMulti. Missing isMulti is especially risky given the existing isMulti/multiple confusion, as dev-mode warnings won't catch type mismatches on either prop.

♻️ Proposed completion
 MuiFormikAsyncAutocomplete.propTypes = {
   name: PropTypes.string.isRequired,
   queryFunction: PropTypes.func.isRequired,
   formatOption: PropTypes.func,
+  formatSelectedValue: PropTypes.func,
   queryParams: PropTypes.array,
+  hiddenOptions: PropTypes.array,
+  multiple: PropTypes.bool,
+  isMulti: PropTypes.bool,
+  plainValue: PropTypes.bool,
   localFilter: PropTypes.bool,
+  placeholder: PropTypes.string,
 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/mui/formik-inputs/mui-formik-async-select.js` around lines 158
- 164, The propTypes for MuiFormikAsyncAutocomplete are missing six props
(multiple, placeholder, plainValue, hiddenOptions, formatSelectedValue,
isMulti); update the MuiFormikAsyncAutocomplete.propTypes object to include
these properties with appropriate types (multiple: PropTypes.bool, isMulti:
PropTypes.bool, placeholder: PropTypes.string, plainValue: PropTypes.bool,
hiddenOptions: PropTypes.array, formatSelectedValue: PropTypes.func) so React
dev-mode warnings catch misuse, and ensure the component’s defaultProps (if any)
and internal logic treat isMulti and multiple consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@src/components/mui/formik-inputs/mui-formik-async-select.js`:
- Around line 115-118: The filterOptions callback in mui-formik-async-select.js
can throw when an option has a null/undefined label; update the filter function
used by filterOptions (the arrow function in that file) to defensively coerce
the label to a string before calling toLowerCase (e.g., use (opt && (opt.label
?? '')) or String(opt?.label ?? '') then toLowerCase) and also guard against opt
being falsy, so options with missing labels no longer crash the filtering logic.
- Around line 42-43: The component mixes two names for the same concept: use the
single prop name isMulti everywhere to avoid shape mismatches. Update the
handleChange function to branch on isMulti (not multiple), ensure the
Autocomplete is passed multiple={isMulti}, and remove/normalize any use of a
separate multiple prop in the component props/destructuring so Formik always
receives the value shape that matches Autocomplete's multiple={isMulti}
behavior.

---

Nitpick comments:
In `@src/components/mui/formik-inputs/mui-formik-async-select.js`:
- Around line 158-164: The propTypes for MuiFormikAsyncAutocomplete are missing
six props (multiple, placeholder, plainValue, hiddenOptions,
formatSelectedValue, isMulti); update the MuiFormikAsyncAutocomplete.propTypes
object to include these properties with appropriate types (multiple:
PropTypes.bool, isMulti: PropTypes.bool, placeholder: PropTypes.string,
plainValue: PropTypes.bool, hiddenOptions: PropTypes.array, formatSelectedValue:
PropTypes.func) so React dev-mode warnings catch misuse, and ensure the
component’s defaultProps (if any) and internal logic treat isMulti and multiple
consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 043e6bbb-fe41-4edc-962a-955e38345598

📥 Commits

Reviewing files that changed from the base of the PR and between c31bbc0 and ae683f6.

📒 Files selected for processing (4)
  • src/components/index.js
  • src/components/mui/formik-inputs/mui-formik-async-select.js
  • src/components/mui/formik-inputs/mui-formik-color-input.js
  • webpack.common.js
✅ Files skipped from review due to trivial changes (1)
  • src/components/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/mui/formik-inputs/mui-formik-color-input.js

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants