Skip to content

Commit

Permalink
createElement; comments
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsongl committed Jul 14, 2020
1 parent f3f8730 commit 3165f5f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLElement, EuiButtonDisplayProps>(
(
{
children,
Expand All @@ -127,7 +126,7 @@ const EuiButtonDisplay = React.forwardRef<
contentProps,
textProps,
fullWidth,
element: Element = 'button',
element = 'button',
...rest
},
ref
Expand Down Expand Up @@ -167,11 +166,14 @@ const EuiButtonDisplay = React.forwardRef<
</EuiButtonContent>
);

return (
// @ts-ignore difficult to verify `rest` applied to `Element`
<Element className={classes} ref={ref} {...rest}>
{innerNode}
</Element>
return React.createElement(
element,
{
className: classes,
ref,
...rest,
},
innerNode
);
}
);
Expand Down Expand Up @@ -209,12 +211,12 @@ export const EuiButton: FunctionComponent<Props> = ({
...rest
}) => {
const buttonIsDisabled = rest.isLoading || isDisabled || disabled;
// <Element> 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 };
}
Expand Down

0 comments on commit 3165f5f

Please sign in to comment.