Skip to content

fix(Button): handle invalid React children for icon props and add Lucid icon picker#7

Closed
garrity-miepub wants to merge 2 commits intomainfrom
feature/button-updates
Closed

fix(Button): handle invalid React children for icon props and add Lucid icon picker#7
garrity-miepub wants to merge 2 commits intomainfrom
feature/button-updates

Conversation

@garrity-miepub
Copy link
Contributor

Added lucid icon options to the button, and dropdowns to preview them on the component

button-updates.mov

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Button component to be more resilient when icon props receive invalid React children, and enhances the Storybook Button stories with a Lucide icon picker to preview left/right icons.

Changes:

  • Guard leftIcon/rightIcon rendering with React.isValidElement to avoid invalid-child runtime errors.
  • Add Storybook controls for selecting Lucide icons for leftIcon and rightIcon.
  • Refresh icon-related stories to use Lucide icons (left, right, and both).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/components/Button/Button.tsx Adds validation before rendering icon props to prevent invalid React child rendering.
src/components/Button/Button.stories.tsx Adds a Lucide icon registry + Storybook controls for icon selection and new icon stories.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Tighten icon prop types to match runtime behavior
  - Changed leftIcon/rightIcon from React.ReactNode to React.ReactElement | null
  - This aligns the type signature with the React.isValidElement() check
  - Prevents silent dropping of strings/numbers/component types

- Remove unused React import from Button.stories.tsx
  - JSX transform (react-jsx) handles React automatically
  - Fixes @typescript-eslint/no-unused-vars lint error

- Fix iconRegistry type safety
  - Changed type from Record<string, LucideIcon> to Record<string, LucideIcon | undefined>
  - Removed unsafe 'as unknown as LucideIcon' cast for None entry
  - Now properly types None: undefined without defeating type-safety
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 26, 2026

Deploying ui with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5e493de
Status: ✅  Deploy successful!
Preview URL: https://b996d532.ui-6d0.pages.dev
Branch Preview URL: https://feature-button-updates.ui-6d0.pages.dev

View logs

garrity-miepub added a commit that referenced this pull request Mar 24, 2026
- Replace hand-rolled menu (useState, useRef, useEffect click-outside,
  useEscapeKey, custom role=menu div, raw button elements) with the
  existing Dropdown/DropdownItem/DropdownSeparator components
- Gets focus management, ARIA attributes, keyboard nav, dark mode,
  and consistent styling for free
- Add DropdownSeparator between normal and destructive actions
- Remove unused imports: React, cn, useEscapeKey
- Net reduction: ~65 lines of custom code

Addresses Copilot review comment #7 on PR #146 (a11y regression).
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