diff --git a/packages/canon/docs/components/LayoutComponents/index.tsx b/packages/canon/docs/components/LayoutComponents/index.tsx
index 16a7a1726c..92fab7c47f 100644
--- a/packages/canon/docs/components/LayoutComponents/index.tsx
+++ b/packages/canon/docs/components/LayoutComponents/index.tsx
@@ -60,7 +60,7 @@ export const LayoutComponents = () => {
Arrange your components in a row
-
+
Container
diff --git a/packages/canon/src/components/Box/Box.tsx b/packages/canon/src/components/Box/Box.tsx
index d134abff35..a470c0584d 100644
--- a/packages/canon/src/components/Box/Box.tsx
+++ b/packages/canon/src/components/Box/Box.tsx
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-import { createElement } from 'react';
+import { createElement, forwardRef } from 'react';
import { boxSprinkles } from './sprinkles.css';
import { base } from './box.css';
import { BoxProps } from './types';
/** @public */
-export const Box = (props: BoxProps) => {
+export const Box = forwardRef
((props, ref) => {
const { as = 'div', className, style, children, ...restProps } = props;
// Generate the list of class names
@@ -32,8 +32,9 @@ export const Box = (props: BoxProps) => {
.join(' ');
return createElement(as, {
+ ref,
className: classNames,
style,
children,
});
-};
+});
diff --git a/packages/canon/src/components/Grid/Grid.tsx b/packages/canon/src/components/Grid/Grid.tsx
index 8e426ff49b..51f60afe27 100644
--- a/packages/canon/src/components/Grid/Grid.tsx
+++ b/packages/canon/src/components/Grid/Grid.tsx
@@ -14,12 +14,18 @@
* limitations under the License.
*/
-import { createElement } from 'react';
+import { createElement, forwardRef } from 'react';
import { GridItemProps, GridProps } from './types';
import { gridItemSprinkles, gridSprinkles } from './sprinkles.css';
+type GridComponent = React.ForwardRefExoticComponent<
+ GridProps & React.RefAttributes
+> & {
+ Item: typeof GridItem;
+};
+
/** @public */
-export const Grid = (props: GridProps) => {
+export const Grid = forwardRef((props, ref) => {
const {
children,
columns,
@@ -42,14 +48,15 @@ export const Grid = (props: GridProps) => {
return createElement(
'div',
{
+ ref,
className: classNames,
style,
},
children,
);
-};
+}) as GridComponent;
-const GridItem = (props: GridItemProps) => {
+const GridItem = forwardRef((props, ref) => {
const { children, rowSpan, colSpan, start, end, className, style } = props;
const sprinklesClassName = gridItemSprinkles({
@@ -63,7 +70,15 @@ const GridItem = (props: GridItemProps) => {
.filter(Boolean)
.join(' ');
- return createElement('div', { className: classNames, style }, children);
-};
+ return createElement(
+ 'div',
+ {
+ ref,
+ className: classNames,
+ style,
+ },
+ children,
+ );
+});
Grid.Item = GridItem;
diff --git a/packages/canon/src/components/Inline/Inline.tsx b/packages/canon/src/components/Inline/Inline.tsx
index a46d4dc948..b583b2ae08 100644
--- a/packages/canon/src/components/Inline/Inline.tsx
+++ b/packages/canon/src/components/Inline/Inline.tsx
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { createElement } from 'react';
+import { createElement, forwardRef } from 'react';
import { inlineSprinkles } from './sprinkles.css';
import type { InlineProps } from './types';
@@ -33,7 +33,7 @@ const alignToFlexAlignY = (align: InlineProps['align']) => {
};
/** @public */
-export const Inline = (props: InlineProps) => {
+export const Inline = forwardRef((props, ref) => {
const {
as = 'div',
children,
@@ -59,8 +59,9 @@ export const Inline = (props: InlineProps) => {
.join(' ');
return createElement(as, {
+ ref,
className: classNames,
style,
children,
});
-};
+});
diff --git a/packages/canon/src/components/Stack/Stack.tsx b/packages/canon/src/components/Stack/Stack.tsx
index 85a67db05d..e0c36f2043 100644
--- a/packages/canon/src/components/Stack/Stack.tsx
+++ b/packages/canon/src/components/Stack/Stack.tsx
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { createElement } from 'react';
+import { createElement, forwardRef } from 'react';
import { StackProps } from './types';
import { stackSprinkles } from './sprinkles.css';
@@ -26,7 +26,7 @@ const alignToFlexAlign = (align: StackProps['align']) => {
};
/** @public */
-export const Stack = (props: StackProps) => {
+export const Stack = forwardRef((props, ref) => {
const {
as = 'div',
children,
@@ -53,8 +53,9 @@ export const Stack = (props: StackProps) => {
.join(' ');
return createElement(as, {
+ ref,
className: classNames,
style,
children,
});
-};
+});