Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 426/button onclick keyboard #447

Merged
merged 1 commit into from
May 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/react/src/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface Props extends PressEvents, FocusableProps, AriaButtonProps {
ripple?: boolean;
icon?: React.ReactNode;
iconRight?: React.ReactNode;
// @deprecated
onClick?: React.MouseEventHandler<HTMLButtonElement>;
as?: keyof JSX.IntrinsicElements;
className?: string;
Expand Down Expand Up @@ -101,6 +102,8 @@ const Button = React.forwardRef(
const handlePress = (e: PressEvent) => {
if (e.pointerType === 'keyboard' || e.pointerType === 'virtual') {
handleDrip(e);
// TODO: take this out and deprecate onClick function for next release (only use the @react-aria/button impl)
onClick?.(e as any);
}
onPress?.(e);
};
Expand All @@ -109,6 +112,7 @@ const Button = React.forwardRef(
const { buttonProps, isPressed } = useButton(
{
...btnProps,
onClick: handleClick,
isDisabled: disabled,
elementType: as,
onPress: handlePress
Expand All @@ -135,9 +139,6 @@ const Button = React.forwardRef(
buttonRef
);

// TODO: remove this when we can use the new onPress(e) => e.clientX && e.clientY API
buttonProps.onClick = handleClick;

/* eslint-enable @typescript-eslint/no-unused-vars */
if (__DEV__ && filteredProps.color === 'gradient' && (flat || light)) {
useWarning(
Expand Down