-
Notifications
You must be signed in to change notification settings - Fork 51
Feature: Allow passing all Button Props through ClipboardButton component #399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 enhances the ClipboardButton component by making it more flexible and allowing consumers to pass additional button props. The component now extends ButtonProps, properly handles external refs, and makes several props optional with sensible defaults.
Key Changes:
- Extended
ClipboardButtonPropsto accept all standard button props exceptchildren - Made
disabled,labels, andonSuccessprops optional - Implemented proper ref merging to handle both internal and external refs
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| const ref = useCopyToClipboard(text, successfullyCopied); | ||
| const mergedRefs = useMergeRefs([ref, (rest.ref as any) || null]); |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ref property should be extracted from rest before spreading to avoid passing it twice to the Button component. Destructure ref from rest at the component parameter level alongside other props.
| } | ||
|
|
||
| const ref = useCopyToClipboard(text, successfullyCopied); | ||
| const mergedRefs = useMergeRefs([ref, (rest.ref as any) || null]); |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using as any type assertion. Instead, properly type the ref or use type guards to ensure type safety.
| const mergedRefs = useMergeRefs([ref, (rest.ref as any) || null]); | |
| const validRef = | |
| typeof rest.ref === 'function' || | |
| (rest.ref && typeof rest.ref === 'object' && 'current' in rest.ref) | |
| ? rest.ref | |
| : null; | |
| const mergedRefs = useMergeRefs([ref, validRef]); |
|
|
||
| return ( | ||
| <Button disabled={disabled} ref={ref}> | ||
| <Button {...(rest as any)} ref={mergedRefs}> |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The as any type assertion bypasses type checking. Since rest should already be typed as Partial<Omit<ButtonProps, 'children'>>, the assertion is unnecessary and should be removed.
| <Button {...(rest as any)} ref={mergedRefs}> | |
| <Button {...rest} ref={mergedRefs}> |
| * Function to run when the text is successfully copied. | ||
| */ | ||
| onSuccess: Function; | ||
| onSuccess?: Function; |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a specific function signature instead of the generic Function type. Consider defining it as onSuccess?: () => void for better type safety.
| onSuccess?: Function; | |
| onSuccess?: () => void; |
10up Block Components
|
||||||||||||||||||||||||||||
| Project |
10up Block Components
|
| Branch Review |
feature/clipboard-button-rest-props
|
| Run status |
|
| Run duration | 04m 55s |
| Commit |
|
| Committer | Fabian Kägy |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
35
|
| View all changes introduced in this branch ↗︎ | |
Closes #398
This pull request refactors the
ClipboardButtoncomponent to improve its flexibility and integration with other components. The main changes focus on making the button props more extensible, handling refs correctly, and making some props optional.Component API improvements
ClipboardButtonPropsinterface now extends the baseButtonprops (usingPartial<Omit<ButtonProps, 'children'>>), allowing the component to accept any valid button prop except forchildren. This makes the component more flexible and easier to use in different contexts.disabled,labels, andonSuccessprops are now optional, providing sensible defaults and reducing the need for boilerplate when using the component. [1] [2]Ref handling improvements
useMergeRefs, ensuring that both internal and external refs are handled correctly when the button is used in more complex scenarios.Usage and rendering changes
rest) onto the underlyingButtoncomponent, further improving extensibility and allowing for easier customization.