From 3165f5fa569893939b4bb1ff128554744dd41b08 Mon Sep 17 00:00:00 2001 From: Greg Thompson Date: Tue, 14 Jul 2020 08:49:19 -0700 Subject: [PATCH] createElement; comments --- src/components/button/button.tsx | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/components/button/button.tsx b/src/components/button/button.tsx index dd265f5fe86..0652e58da6a 100644 --- a/src/components/button/button.tsx +++ b/src/components/button/button.tsx @@ -108,11 +108,10 @@ export interface EuiButtonDisplayProps extends EuiButtonProps { /** * * *INTERNAL ONLY* Component for displaying any element as a button + * EuiButton is largely responsible for providing relevant props + * and the logic for element-specific attributes */ -const EuiButtonDisplay = React.forwardRef< - HTMLAnchorElement | HTMLButtonElement | HTMLLabelElement, - EuiButtonDisplayProps ->( +const EuiButtonDisplay = React.forwardRef( ( { children, @@ -127,7 +126,7 @@ const EuiButtonDisplay = React.forwardRef< contentProps, textProps, fullWidth, - element: Element = 'button', + element = 'button', ...rest }, ref @@ -167,11 +166,14 @@ const EuiButtonDisplay = React.forwardRef< ); - return ( - // @ts-ignore difficult to verify `rest` applied to `Element` - - {innerNode} - + return React.createElement( + element, + { + className: classes, + ref, + ...rest, + }, + innerNode ); } ); @@ -209,12 +211,12 @@ export const EuiButton: FunctionComponent = ({ ...rest }) => { const buttonIsDisabled = rest.isLoading || isDisabled || disabled; - // elements don't respect the `disabled` attribute. So if we're disabled, we'll just pretend - // this is a button and piggyback off its disabled styles. const element = href && !isDisabled ? 'a' : 'button'; let elementProps = {}; + // Props for all elements elementProps = { ...elementProps, isDisabled: buttonIsDisabled }; + // Element-specific attributes if (element === 'button') { elementProps = { ...elementProps, disabled: buttonIsDisabled }; }