feat(ActionButton): use button component for action button#1358
feat(ActionButton): use button component for action button#1358ethanashaw wants to merge 1 commit intomainfrom
Conversation
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
Updates ActionButton to render the shared Button component so it can accept additional Button props (e.g. hasIcon), and demonstrates this in Storybook via ConfirmationModal.
Changes:
- Switch
ActionButtonfrom a native<button>to the shared<Button>component and widen its spread props toButtonProps. - Attempt to add ref support to
Buttonvia arefprop. - Update
ConfirmationModalStorybook story to show an icon + label confirm button usinghasIcon.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/components/ActionButton/ActionButton.tsx | Renders Button instead of native button and expands accepted props to ButtonProps. |
| src/components/Button/Button.tsx | Adds a ref field to the exported prop type in an attempt to support refs. |
| src/components/ConfirmationModal/ConfirmationModal.stories.tsx | Demonstrates icon+label confirm button using confirmButtonProps.hasIcon. |
Comments suppressed due to low confidence (1)
src/components/ActionButton/ActionButton.tsx:180
ActionButtonrelies onref.currentto measure the button size, but passingref={ref}to<Button />will not attach the ref unlessButtonforwards refs. As-is,ref.currentwill stay null and the loader sizing logic won’t run. Either switchButtontoforwardRef(preferred) or revert this component to rendering a native<button>and manually apply the needed Button classes/props.
<Button
className={buttonClasses}
ref={ref}
onClick={isDisabled ? onClickDisabled : onClick}
aria-disabled={isDisabled || undefined}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * A ref to the button. | ||
| */ | ||
| ref?: Ref<HTMLButtonElement>; | ||
| } & (Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onClick"> | P); |
There was a problem hiding this comment.
Adding a ref prop to Button doesn’t actually make <Button ref={...} /> work: React treats ref as a special attribute, so it won’t be delivered via props to this function component (and will emit a runtime warning). To support refs, convert Button to React.forwardRef and pass the forwarded ref to the underlying element (and remove ref from the regular props shape / use RefAttributes).
| <Button | ||
| className={buttonClasses} | ||
| ref={ref} | ||
| onClick={isDisabled ? onClickDisabled : onClick} |
There was a problem hiding this comment.
Now that ActionButton renders <Button>, the appearance ? \p-button--${appearance}` : "p-button"class inbuttonClassescombines withButton’s own default p-buttonclass (sinceappearanceisn’t passed through), changing the rendered class list vs before (e.g.p-button p-button--negative). Pass appearance={appearance}toButtonand remove thep-button...portion frombuttonClassesto keep styling consistent with theButton` component.
| // This component uses the base button element instead of the Button component | ||
| // as the button requires a ref and Button would have to be updated to use | ||
| // forwardRef which is not currently supported by components that use | ||
| // typescript generics. | ||
| return ( | ||
| <button | ||
| <Button |
There was a problem hiding this comment.
The comment above the return still says this component uses a native button because Button doesn’t support refs, but the implementation now renders <Button>. Please update/remove the comment so it matches the new behavior (and the chosen ref strategy).
| import Icon from "components/Icon"; | ||
|
|
||
| const doNothing = () => {}; | ||
| const doNothing = () => { }; |
There was a problem hiding this comment.
Formatting: the codebase’s stories consistently use const doNothing = () => {}; (e.g. src/components/ConfirmationButton/ConfirmationButton.stories.tsx:8). Please remove the extra spaces (() => { };) to match existing conventions.
| const doNothing = () => { }; | |
| const doNothing = () => {}; |
Done
I changed
ActionButtonto use theButtoncomponent instead of the default HTMLbutton, allowing for the extra props.I made a change to one of the
ConfirmationModalstories showing this off. We needed to include an icon for a confirmation button, but the button couldn't be styled with thehasIconprop before.QA
Pinging @canonical/react-library-maintainers for a review.
Storybook
To see rendered examples of all react-components, run:
QA in your project
from
react-componentsrun:Install the resulting tarball in your project with:
QA steps
Percy steps