<commit_before>// @flow
import * as React from 'react';
import type { ColorProps } from '../themes/types';
import Text, { type TextProps } from './Text';
import withTheme from './withTheme';

// Browser button is rendered as div with button role because button element is
// hard to style consistently in Firefox and maybe elsewhere. Div is just fine.
// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role
const BrowserButton = ({
  disabled,
  onPress,
  style,
  ...props
}: {
  disabled?: boolean,
  onPress: () => void,
  style?: Object,
}) => (
  <div // eslint-disable-line jsx-a11y/no-static-element-interactions
    onClick={onPress}
    onKeyPress={(e: KeyboardEvent) => {
      if (disabled) return;
      // Buttons are expected to be triggered using the Space or Enter key.
      const isTriggered = e.key === ' ' || e.key === 'Enter';
      if (!isTriggered) return;
      // Prevent scroll on spacebar press.
      e.preventDefault();
      onPress();
    }}
    role="button"
    tabIndex={disabled ? -1 : 0}
    style={{
      ...style,
      cursor: disabled ? 'default' : 'pointer',
      pointerEvents: disabled ? 'none' : 'auto',
      userSelect: 'none',
      MozUserSelect: 'none',
      WebkitUserSelect: 'none',
    }}
    {...props}
  />
);

export type ButtonProps = ColorProps &
  TextProps & {
    disabled?: boolean,
    onPress?: () => any,<commit_msg>Fix Button onKeyPress bug<commit_after>// @flow
import * as React from 'react';
import type { ColorProps } from '../themes/types';
import Text, { type TextProps } from './Text';
import withTheme from './withTheme';

// Browser button is rendered as div with button role because button element is
// hard to style consistently in Firefox and maybe elsewhere. Div is just fine.
// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role
const BrowserButton = ({
  disabled,
  onPress,
  style,
  ...props
}: {
  disabled?: boolean,
  onPress?: () => void,
  style?: Object,
}) => (
  <div // eslint-disable-line jsx-a11y/no-static-element-interactions
    onClick={onPress}
    onKeyPress={(e: KeyboardEvent) => {
      if (!onPress) return;
      if (disabled) return;
      // Buttons are expected to be triggered using the Space or Enter key.
      const isTriggered = e.key === ' ' || e.key === 'Enter';
      if (!isTriggered) return;
      // Prevent scroll on spacebar press.
      e.preventDefault();
      onPress();
    }}
    role="button"
    tabIndex={disabled ? -1 : 0}
    style={{
      ...style,
      cursor: disabled ? 'default' : 'pointer',
      pointerEvents: disabled ? 'none' : 'auto',
      userSelect: 'none',
      MozUserSelect: 'none',
      WebkitUserSelect: 'none',
    }}
    {...props}
  />
);

export type ButtonProps = ColorProps &
  TextProps & {
    disabled?: boolean,
    onPress?: () => any,
{'fraction_non_alphanumeric': 0.14609831557236164, 'fraction_numerical': 0.002750085940185631, 'mean_word_length': 2.874833555259654, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5283850', 'n_tokens_mistral': 895, 'n_tokens_neox': 886, 'n_words': 259}