From 9db62df2442845081505056994dfc66caf5ae9cb Mon Sep 17 00:00:00 2001 From: Anish Aggarwal Date: Sun, 1 Mar 2020 00:03:52 +0530 Subject: [PATCH 1/3] eui button now has a single return statement --- CHANGELOG.md | 1 + src/components/button/button.tsx | 36 ++++++++++++-------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e70017473dd..55d77de3d64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## [`master`](https://github.com/elastic/eui/tree/master) +- `EuiButton` now has a single return statement ([#2896](https://github.com/elastic/eui/pull/2896)) - 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)) - Added default prompt text to `aria-describedby` for `EuiFilePicker` ([#2919](https://github.com/elastic/eui/pull/2919)) diff --git a/src/components/button/button.tsx b/src/components/button/button.tsx index 34fa662a64a..24bfbd6451d 100644 --- a/src/components/button/button.tsx +++ b/src/components/button/button.tsx @@ -1,9 +1,8 @@ import React, { - AnchorHTMLAttributes, - ButtonHTMLAttributes, FunctionComponent, HTMLAttributes, Ref, + ButtonHTMLAttributes, } from 'react'; import classNames from 'classnames'; @@ -165,33 +164,24 @@ export const EuiButton: FunctionComponent = ({ ); - // elements don't respect the `disabled` attribute. So if we're disabled, we'll just pretend + // 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. - if (href && !isDisabled) { - const secureRel = getSecureRelForTarget({ href, target, rel }); - - return ( - } - {...rest as AnchorHTMLAttributes}> - {innerNode} - - ); - } + const Element = href && !isDisabled ? 'a' : 'button'; + const secureRel = getSecureRelForTarget({ href, target, rel }); let buttonType: ButtonHTMLAttributes['type']; + return ( - + ); }; From b3fe9ebd998cb3e9dab458ca22ac7c10016286b6 Mon Sep 17 00:00:00 2001 From: Anish Aggarwal Date: Sun, 1 Mar 2020 15:46:57 +0530 Subject: [PATCH 2/3] updated for rel --- CHANGELOG.md | 2 +- src/components/button/button.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55d77de3d64..581033ecb13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## [`master`](https://github.com/elastic/eui/tree/master) -- `EuiButton` now has a single return statement ([#2896](https://github.com/elastic/eui/pull/2896)) +- `EuiButton` now has a single return statement ([#2954](https://github.com/elastic/eui/pull/2954)) - 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)) - Added default prompt text to `aria-describedby` for `EuiFilePicker` ([#2919](https://github.com/elastic/eui/pull/2919)) diff --git a/src/components/button/button.tsx b/src/components/button/button.tsx index 24bfbd6451d..ced08e53a74 100644 --- a/src/components/button/button.tsx +++ b/src/components/button/button.tsx @@ -167,8 +167,10 @@ export const EuiButton: FunctionComponent = ({ // 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 } = {}; + if (href && !isDisabled) + relObj.rel = getSecureRelForTarget({ href, target, rel }); - const secureRel = getSecureRelForTarget({ href, target, rel }); let buttonType: ButtonHTMLAttributes['type']; return ( @@ -177,7 +179,7 @@ export const EuiButton: FunctionComponent = ({ disabled={isDisabled} href={href} target={target} - rel={secureRel} + {...relObj} ref={buttonRef as Ref} type={type as typeof buttonType} {...rest as HTMLAttributes}> From 86a61270156eb82242f87e83de13e269cee7a2ba Mon Sep 17 00:00:00 2001 From: Anish Aggarwal Date: Sun, 1 Mar 2020 23:10:04 +0530 Subject: [PATCH 3/3] removed non-exesting attribues for button and anchor tag --- src/components/button/button.tsx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/components/button/button.tsx b/src/components/button/button.tsx index ced08e53a74..e39047933c3 100644 --- a/src/components/button/button.tsx +++ b/src/components/button/button.tsx @@ -167,21 +167,28 @@ export const EuiButton: FunctionComponent = ({ // 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 } = {}; - if (href && !isDisabled) - relObj.rel = getSecureRelForTarget({ href, target, rel }); - let buttonType: ButtonHTMLAttributes['type']; + const relObj: { + rel?: string; + href?: string; + type?: ButtonHTMLAttributes['type']; + target?: string; + } = {}; + + if (href && !isDisabled) { + relObj.href = href; + relObj.rel = getSecureRelForTarget({ href, target, rel }); + relObj.target = target; + } else { + relObj.type = type as ButtonHTMLAttributes['type']; + } return ( } - type={type as typeof buttonType} {...rest as HTMLAttributes}> {innerNode}