fix(ui): forward HTML attributes on Box component

Extended BoxProps to include React.HTMLAttributes<HTMLDivElement>
and spread restProps onto the rendered element. This allows
standard HTML attributes like onClick, aria-*, data-*, etc. to
be passed through to the underlying div.

Signed-off-by: Johan Persson <johanopersson@gmail.com>
This commit is contained in:
Johan Persson
2026-01-27 10:46:39 +01:00
parent 7fd67d79aa
commit 350c948453
4 changed files with 19 additions and 3 deletions
+7
View File
@@ -0,0 +1,7 @@
---
'@backstage/ui': patch
---
Fixed Box component to forward HTML attributes to the underlying div element.
**Affected components:** Box
+5 -1
View File
@@ -282,7 +282,11 @@ export type BoxOwnProps = {
};
// @public (undocumented)
export interface BoxProps extends SpaceProps, BoxOwnProps, BoxUtilityProps {}
export interface BoxProps
extends SpaceProps,
BoxOwnProps,
BoxUtilityProps,
React.HTMLAttributes<HTMLDivElement> {}
// @public (undocumented)
export type BoxUtilityProps = {
+2 -1
View File
@@ -21,7 +21,7 @@ import { BoxDefinition } from './definition';
/** @public */
export const Box = forwardRef<HTMLDivElement, BoxProps>((props, ref) => {
const { ownProps, dataAttributes, utilityStyle } = useDefinition(
const { ownProps, restProps, dataAttributes, utilityStyle } = useDefinition(
BoxDefinition,
props,
);
@@ -34,6 +34,7 @@ export const Box = forwardRef<HTMLDivElement, BoxProps>((props, ref) => {
className: classes.root,
style: { ...ownProps.style, ...utilityStyle },
...dataAttributes,
...restProps,
},
surfaceChildren,
);
+5 -1
View File
@@ -41,4 +41,8 @@ export type BoxUtilityProps = {
};
/** @public */
export interface BoxProps extends SpaceProps, BoxOwnProps, BoxUtilityProps {}
export interface BoxProps
extends SpaceProps,
BoxOwnProps,
BoxUtilityProps,
React.HTMLAttributes<HTMLDivElement> {}