Skip to content

fix: fall back to the default instead of crashing on a removed IconButton/FAB prop value - #5315

Open
biggdawg320 wants to merge 1 commit into
callstack:mainfrom
biggdawg320:jobscout/5309-iconbutton-appbar-action-textinput-icon
Open

biggdawg320 wants to merge 1 commit into
callstack:mainfrom
biggdawg320:jobscout/5309-iconbutton-appbar-action-textinput-icon

Conversation

@biggdawg320

Copy link
Copy Markdown

Motivation

IconButton's mode/size and FAB's variant indexed straight into their token maps. A value that 6.x removed — 5.x's contained/contained-tonal modes, a numeric size, or a 6.0-alpha FAB variant such as tonalPrimary or surface — crashed the render with a TypeError that named neither the prop nor the value that replaces it. Since Appbar.Action and TextInput.Icon forward size/mode straight through to IconButtonProps, they crashed the same way.

Related issue

Screenshots / Videos

Not applicable: this is a logic fix with no visual change for valid prop values. An invalid value now renders with the component's existing default appearance instead of crashing.

Test plan

  • Added removed 5.x prop values tests in src/components/__tests__/IconButton.test.tsx covering a removed mode and a numeric size, asserting the resolved value matches the default and that console.warn fires once (via the component's effect) with the rejected value.
  • Added a falls back instead of crashing on a removed variant value test in src/components/__tests__/FAB.test.tsx for an invalid FAB variant, and a matching pure fallback test in src/components/__tests__/FABUtils.test.tsx.
  • Ran yarn jest src/components/__tests__/IconButton.test.tsx src/components/__tests__/FAB.test.tsx src/components/__tests__/FABUtils.test.tsx src/components/__tests__/TextInput.test.tsx src/components/__tests__/Appbar/Appbar.test.tsx --coverage=false to confirm the new tests pass and nothing else regressed.

This change was drafted with AI assistance (Claude) and verified against the project's test suite.

Fixes #5309

… value

IconButton's `mode` and `size`, and FAB's `variant`, indexed straight into
their token maps, so a value that 6.x removed (or any other string cast
past the types, such as 5.x's `contained`/`contained-tonal` modes, a
numeric `size`, or a 6.0-alpha FAB variant like `tonalPrimary`) crashed
with a TypeError that named neither the prop nor its replacement.
Appbar.Action and TextInput.Icon hit the same crash, since both forward
`size`/`mode` straight through to IconButton.

Resolve the value against the token map before using it, falling back
to the documented default ("standard" mode, "small" size, the
"primaryContainer" FAB variant). The resolvers stay pure; IconButton and
FAB's Shell warn once per change, in a `useEffect` keyed on the prop,
following the same dev-warning convention as Switch and TextInput.Icon
instead of warning on every render.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Found potential problems with the pull request:

  • The description is too long. Please keep it under 1000 characters.
  • Screenshot or video evidence is missing. Make sure to include one if it affects the UI.

@Doberjohn Doberjohn added this to the 6.1.0 milestone Nov 24, 2026

This branch has not been deployed

No deployments
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.

IconButton, Appbar.Action, TextInput.Icon and FAB crash on a removed 5.x prop value instead of warning

2 participants