Skip to content

fix: improve Button component accessibility and reusability - Add typ… #42 - #44

Open
ankitrraj wants to merge 1 commit into
DjedAlliance:mainfrom
ankitrraj:fix/button-accessibility
Open

fix: improve Button component accessibility and reusability - Add typ… #42#44
ankitrraj wants to merge 1 commit into
DjedAlliance:mainfrom
ankitrraj:fix/button-accessibility

Conversation

@ankitrraj

@ankitrraj ankitrraj commented Dec 14, 2025

Copy link
Copy Markdown

…e=button as default, accept all HTML button props, add TypeScript interface, add hover/active/disabled states - Fixes #42

Summary by CodeRabbit

  • New Features

    • Button component now supports variant options (primary and secondary) for flexible styling.
    • Enhanced disabled button states with smooth visual transitions for improved user feedback.
  • Refactor

    • Strengthened Button component with improved type definitions and native HTML button attribute support.

✏️ Tip: You can customize this high-level summary in your review settings.

…e=button as default, accept all HTML button props, add TypeScript interface, add hover/active/disabled states - Fixes DjedAlliance#42
@coderabbitai

coderabbitai Bot commented Dec 14, 2025

Copy link
Copy Markdown

Walkthrough

The Button component was refactored to improve type safety and prop handling. A new ButtonProps interface was introduced to explicitly define supported props including a variant option. The className computation now uses twMerge to intelligently merge hardcoded styles with passed className props. Native HTML button attributes are exposed via prop spreading, and children rendering was simplified for clarity.

Changes

Cohort / File(s) Summary
Button Component Enhancement
src/components/Button.tsx
Introduced strongly-typed ButtonProps interface extending React.ButtonHTMLAttributes<HTMLButtonElement> with optional variant ('primary' | 'secondary') parameter. Updated function signature with explicit prop destructuring (children, className, variant, type, ...props). Switched className handling to twMerge() for merging hardcoded classes with incoming className values, ensuring proper Tailwind CSS collision handling. Added spread operator (...props) to expose native button attributes (e.g., disabled, onClick, aria-*). Refactored children rendering to use direct children parameter within <span className="relative"> wrapper.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Areas requiring attention:
    • Verify twMerge is correctly imported and properly merges the hardcoded button classes with any user-provided className
    • Confirm the ButtonProps interface correctly extends React.ButtonHTMLAttributes<HTMLButtonElement> and doesn't inadvertently override needed attributes
    • Review the prop spreading order to ensure ...props doesn't unintentionally override explicit parameters like type or className

Suggested reviewers

  • Tanya-ruby

Poem

🐰 A Button so plain now shines with might,
With types and variants, styled just right!
TailwindCSS classes dance and merge,
Props spread freely—let them emerge!
twMerge whispers magic in the breeze,
Our little Button now aims to please! ✨

Pre-merge checks and finishing touches

❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR title and description claim to fix issue #42, but the changes are to the Button component, not the mobile navigation menu objectives in issue #42. Verify the correct linked issue number. If this fixes #42, ensure the PR includes mobile navigation changes. Otherwise, link to the correct issue.
Out of Scope Changes check ⚠️ Warning The Button component refactoring appears unrelated to issue #42's mobile navigation menu requirements (drawer, backdrop overlay, animations, accessibility attributes). Either link this PR to a Button component improvement issue, or include the mobile navigation menu changes required by issue #42.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 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 changes: improving Button component with accessibility enhancements and reusability through TypeScript typing and prop handling.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@ankitrraj

Copy link
Copy Markdown
Author
image

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/components/Button.tsx (1)

15-30: Accessibility + reusability: add focus-visible styles and merge style instead of letting props.style wipe defaults.
Right now, passing style via props will override (and remove) the default boxShadow because ...props comes after style.

 export function Button({
   children,
   className,
   variant = 'primary',
   type = 'button',
+  style,
   ...props
 }: ButtonProps) {
   return (
     <button
       type={type}
       className={twMerge(
-        'relative py-1.5 px-2.5 sm:py-2 sm:px-3 rounded-lg font-medium text-xs sm:text-sm bg-gradient-to-b from-[#331500] to-[#FF863B] transition-transform hover:scale-105 active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:scale-100',
+        'relative py-1.5 px-2.5 sm:py-2 sm:px-3 rounded-lg font-medium text-xs sm:text-sm bg-gradient-to-b from-[#331500] to-[#FF863B] transition-transform hover:scale-105 active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:scale-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#FF863B]/70 focus-visible:ring-offset-2 focus-visible:ring-offset-black/20',
         className
       )}
-      style={{ boxShadow: '0 0 12px #FF863B' }}
+      style={{ boxShadow: '0 0 12px #FF863B', ...style }}
       {...props}
     >
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ccf238 and 0eac7cf.

📒 Files selected for processing (1)
  • src/components/Button.tsx (1 hunks)

Comment thread src/components/Button.tsx
Comment on lines +1 to +5
import { twMerge } from 'tailwind-merge'

interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary'
}

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 | 🔴 Critical

Fix missing React type import (current code won’t typecheck/compile).
You reference React.ButtonHTMLAttributes but don’t import React (type). Import it, or stop using the React. namespace.

+import type * as React from 'react'
 import { twMerge } from 'tailwind-merge'
📝 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
import { twMerge } from 'tailwind-merge'
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary'
}
import type * as React from 'react'
import { twMerge } from 'tailwind-merge'
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary'
}
🤖 Prompt for AI Agents
In src/components/Button.tsx around lines 1-5, the component uses
React.ButtonHTMLAttributes but React is not imported causing typecheck failures;
fix by either adding an import for React types (e.g., `import type React from
'react'` or `import React from 'react'` depending on tsconfig) or switch to the
direct type import `import type { ButtonHTMLAttributes } from 'react'` and
update the interface to extend ButtonHTMLAttributes<HTMLButtonElement>; ensure
imports use `import type` when only types are needed to avoid runtime imports.

Comment thread src/components/Button.tsx
Comment on lines +3 to +13
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary'
}

export function Button({
children,
className,
variant = 'primary',
type = 'button',
...props
}: ButtonProps) {

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

variant is part of the public API but currently does nothing.
Either wire it into the className (recommended) or remove it to avoid a misleading prop.

Example wiring:

 export function Button({
   children,
   className,
   variant = 'primary',
   type = 'button',
   ...props
 }: ButtonProps) {
+  const variantClasses =
+    variant === 'secondary'
+      ? 'from-slate-700 to-slate-900'
+      : 'from-[#331500] to-[#FF863B]'
   return (
     <button
       type={type}
       className={twMerge(
-        'relative py-1.5 px-2.5 sm:py-2 sm:px-3 rounded-lg font-medium text-xs sm:text-sm bg-gradient-to-b from-[#331500] to-[#FF863B] transition-transform hover:scale-105 active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:scale-100',
+        'relative py-1.5 px-2.5 sm:py-2 sm:px-3 rounded-lg font-medium text-xs sm:text-sm bg-gradient-to-b transition-transform hover:scale-105 active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:scale-100',
+        variantClasses,
         className
       )}

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/components/Button.tsx around lines 3 to 13, the exported Button accepts a
variant prop but never uses it; either remove the prop or apply it to the
rendered element. Fix by mapping variant to CSS classes (e.g. determine a base
className and append variant-specific classes for 'primary' and 'secondary'),
merge with any incoming className, and pass the combined className to the button
element; keep default variant='primary' and preserve other props.

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.

1 participant