Skip to content

Commit

Permalink
eui button now has a single return statement (#2954)
Browse files Browse the repository at this point in the history
* eui button now has a single return statement

* updated for rel

* removed non-exesting attribues for button and anchor tag
  • Loading branch information
anishagg17 authored Mar 2, 2020
1 parent 72ee607 commit aea12fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- `EuiButton` now has a single return statement ([#2954](https://github.com/elastic/eui/pull/2954))
- Added `isSortable` props to `EuiDataGridColumn` and `EuiDataGridSchemaDetector` to mark them as un-sortable ([#2952](https://github.com/elastic/eui/pull/2952))
- Converted `EuiForm` to TypeScript, added many missing `/form` Prop types ([#2896](https://github.com/elastic/eui/pull/2896))
- Empty table th elements replaced with td in `EuiTable`. ([#2934](https://github.com/elastic/eui/pull/2934))
Expand Down
45 changes: 22 additions & 23 deletions src/components/button/button.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, {
AnchorHTMLAttributes,
ButtonHTMLAttributes,
FunctionComponent,
HTMLAttributes,
Ref,
ButtonHTMLAttributes,
} from 'react';
import classNames from 'classnames';

Expand Down Expand Up @@ -165,33 +164,33 @@ export const EuiButton: FunctionComponent<Props> = ({
</span>
);

// <a> elements don't respect the `disabled` attribute. So if we're disabled, we'll just pretend
// <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';

const relObj: {
rel?: string;
href?: string;
type?: ButtonHTMLAttributes<HTMLButtonElement>['type'];
target?: string;
} = {};

if (href && !isDisabled) {
const secureRel = getSecureRelForTarget({ href, target, rel });

return (
<a
className={classes}
href={href}
target={target}
rel={secureRel}
ref={buttonRef as Ref<HTMLAnchorElement>}
{...rest as AnchorHTMLAttributes<HTMLAnchorElement>}>
{innerNode}
</a>
);
relObj.href = href;
relObj.rel = getSecureRelForTarget({ href, target, rel });
relObj.target = target;
} else {
relObj.type = type as ButtonHTMLAttributes<HTMLButtonElement>['type'];
}

let buttonType: ButtonHTMLAttributes<HTMLButtonElement>['type'];
return (
<button
disabled={isDisabled}
<Element
className={classes}
type={type as typeof buttonType}
ref={buttonRef as Ref<HTMLButtonElement>}
{...rest as ButtonHTMLAttributes<HTMLButtonElement>}>
disabled={isDisabled}
{...relObj}
ref={buttonRef as Ref<HTMLButtonElement & HTMLAnchorElement>}
{...rest as HTMLAttributes<HTMLAnchorElement | HTMLButtonElement>}>
{innerNode}
</button>
</Element>
);
};

0 comments on commit aea12fa

Please sign in to comment.