Skip to content

Commit

Permalink
Use preventClickFocus on buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Brain authored and Daniel Brain committed May 28, 2020
1 parent 3a2533a commit 58e3f5c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ui/buttons/button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { FundingEligibilityType } from '@paypal/sdk-client/src';
import { FUNDING, ENV, type LocaleType } from '@paypal/sdk-constants/src';
import { node, type ElementNode } from 'jsx-pragmatic/src';
import { LOGO_COLOR, LOGO_CLASS } from '@paypal/sdk-logos/src';
import { noop } from 'belter/src';
import { noop, preventClickFocus, isBrowser, isElement } from 'belter/src';

import type { ContentType, Wallet, WalletInstrument } from '../../types';
import { ATTRIBUTE, CLASS, BUTTON_COLOR, BUTTON_NUMBER, TEXT_COLOR } from '../../constants';
Expand Down Expand Up @@ -87,7 +87,6 @@ export function Button({ fundingSource, style, multiple, locale, env, fundingEli
const clickHandler = (event, opts) => {
event.preventDefault();
event.stopPropagation();
event.target.blur();
onClick(event, { fundingSource, ...opts });
};

Expand All @@ -97,6 +96,12 @@ export function Button({ fundingSource, style, multiple, locale, env, fundingEli
}
};

const onButtonRender = el => {
if (isBrowser() && isElement(el)) {
preventClickFocus(el);
}
};

const { layout, shape } = style;

const labelText = fundingConfig.labelText || fundingSource;
Expand Down Expand Up @@ -166,6 +171,7 @@ export function Button({ fundingSource, style, multiple, locale, env, fundingEli
`${ LOGO_CLASS.LOGO_COLOR }-${ logoColor }`
].join(' ') }
onClick={ clickHandler }
onRender={ onButtonRender }
onKeyPress={ keypressHandler }
tabindex='0'
aria-label={ labelText }>
Expand Down

0 comments on commit 58e3f5c

Please sign in to comment.