feat(ui): default Button to type='button' and forward refs on Button,… - #17
Merged
Mona-i merged 2 commits intoSep 10, 2026
Conversation
… Input, Card - Button now defaults to type='button' to prevent accidental form submissions when no type prop is provided (closes #6) - Wrapped Button, Input, Card, CardTitle, and CardBody with React.forwardRef, typing refs to HTMLButtonElement, HTMLInputElement, and HTMLDivElement/HTMLHeadingElement/HTMLParagraphElement respectively (closes #7) - Set displayName on all forwarded components for readable React DevTools - Added tests: Button default type='button', Button ref forwarding, Input ref forwarding (7/7 tests passing)
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(ui): default Button to
type="button"and forward refs on Button, Input, Cardcloses #6
closes #7
What and why
Two small but impactful improvements to the UI primitives in
@lumio/ui.#6 — Default
Buttontotype="button"An HTML
<button>with notypeattribute defaults totype="submit"per the spec. That means any<Button>placed inside a<form>will submit the form on click — even when it was only meant to trigger a client-side action. This is a silent footgun that is easy to introduce and hard to debug.The fix is a one-line default:
type = "button". Callers who needtype="submit"ortype="reset"still pass it explicitly and it wins, so no existing behaviour is broken.#7 —
forwardRefonButton,Input, andCardThe primitives were plain function components with no ref support. Without
forwardRef, consumers cannot:inputRef.current?.focus()for focus managementreffromreact-hook-form'sregisterorControllerscrollIntoViewon a cardFor a design-system package meant to be consumed by product apps, ref forwarding is table stakes. This change wraps every component (including
CardTitleandCardBody) withReact.forwardRef, types the ref to the correct DOM element, and setsdisplayNameon each so React DevTools remains readable.Changes
packages/ui/src/components/Button.tsxforwardRef<HTMLButtonElement>,type = "button"default,displayName = "Button"packages/ui/src/components/Input.tsxforwardRef<HTMLInputElement>,displayName = "Input"packages/ui/src/components/Card.tsxforwardRefonCard,CardTitle, andCardBodywith correct element types;displayNameon all threepackages/ui/src/ui.test.tsxNo new dependencies. No API changes. All existing prop signatures are preserved.
Tests
Validation
npm run typechecknpm run testnpm run buildOut of scope