From 11f36b2ac9963d3e3693a2b5b834b5a2938fb776 Mon Sep 17 00:00:00 2001 From: Thomas Heyenbrock Date: Sun, 7 Aug 2022 13:08:54 +0200 Subject: [PATCH] forward refs and props for UI components (#2628) --- .../graphiql-react/src/toolbar/button.tsx | 11 ++- .../graphiql-react/src/ui/button-group.tsx | 21 +++-- packages/graphiql-react/src/ui/button.tsx | 55 ++++++----- packages/graphiql-react/src/ui/dialog.tsx | 40 ++++---- packages/graphiql-react/src/ui/markdown.tsx | 28 ++++-- packages/graphiql-react/src/ui/spinner.tsx | 16 +++- packages/graphiql-react/src/ui/tabs.tsx | 92 ++++++++++--------- 7 files changed, 157 insertions(+), 106 deletions(-) diff --git a/packages/graphiql-react/src/toolbar/button.tsx b/packages/graphiql-react/src/toolbar/button.tsx index df802823353..ec6bf5c8f7a 100644 --- a/packages/graphiql-react/src/toolbar/button.tsx +++ b/packages/graphiql-react/src/toolbar/button.tsx @@ -1,14 +1,18 @@ -import { useState } from 'react'; +import { forwardRef, useState } from 'react'; import { UnStyledButton } from '../ui'; import './button.css'; -export function ToolbarButton(props: JSX.IntrinsicElements['button']) { +export const ToolbarButton = forwardRef< + HTMLButtonElement, + JSX.IntrinsicElements['button'] +>((props, ref) => { const [error, setError] = useState(null); return ( ); -} +}); +ToolbarButton.displayName = 'ToolbarButton'; diff --git a/packages/graphiql-react/src/ui/button-group.tsx b/packages/graphiql-react/src/ui/button-group.tsx index 2789150695e..0dee87dc7e7 100644 --- a/packages/graphiql-react/src/ui/button-group.tsx +++ b/packages/graphiql-react/src/ui/button-group.tsx @@ -1,10 +1,15 @@ +import { forwardRef } from 'react'; + import './button-group.css'; -export function ButtonGroup(props: JSX.IntrinsicElements['div']) { - return ( -
- ); -} +export const ButtonGroup = forwardRef< + HTMLDivElement, + JSX.IntrinsicElements['div'] +>((props, ref) => ( +
+)); +ButtonGroup.displayName = 'ButtonGroup'; diff --git a/packages/graphiql-react/src/ui/button.tsx b/packages/graphiql-react/src/ui/button.tsx index 950210116fb..d010196b559 100644 --- a/packages/graphiql-react/src/ui/button.tsx +++ b/packages/graphiql-react/src/ui/button.tsx @@ -1,31 +1,38 @@ +import { forwardRef } from 'react'; import { compose } from '../utility/compose'; import './button.css'; -export function UnStyledButton(props: JSX.IntrinsicElements['button']) { - return ( -