Adding tabIndex prop to Buttons component (#7694)

* tabindex

* Added a test for tabIndex.

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>
This commit is contained in:
ludwiczakpawel 2020-05-06 15:40:09 +02:00 committed by GitHub
parent 3ede8912b8
commit b1bcf2ed9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View file

@ -56,6 +56,7 @@ export const Button = ({
onMouseOut,
onFocus,
onBlur,
tabIndex,
}) => {
const ComponentName = tagName;
const Icon = icon;
@ -81,6 +82,7 @@ export const Button = ({
onMouseOut={onMouseOut}
onFocus={onFocus}
onBlur={onBlur}
tabIndex={tabIndex}
{...otherProps}
>
{contentType !== 'text' && contentType !== 'icon-right' && Icon && (
@ -111,6 +113,7 @@ Button.defaultProps = {
onMouseOut: undefined,
onFocus: undefined,
onBlur: undefined,
tabIndex: undefined,
};
Button.propTypes = {
@ -146,4 +149,5 @@ Button.propTypes = {
onMouseOut: PropTypes.func,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
tabIndex: PropTypes.number,
};

View file

@ -9,6 +9,11 @@ describe('<Button /> component', () => {
expect(tree).toMatchSnapshot();
});
it('should render with a tabIndex', () => {
const tree = render(<Button tabIndex="0">Hello world!</Button>);
expect(tree).toMatchSnapshot();
});
it('should render a secondary button when using the variant "secondary"', () => {
const tree = render(<Button variant="secondary">Hello world!</Button>);
expect(tree).toMatchSnapshot();

View file

@ -127,3 +127,14 @@ exports[`<Button /> component should render an outlined button when using the va
Hello world!
</button>
`;
exports[`<Button /> component should render with a tabIndex 1`] = `
<button
class="crayons-btn"
disabled={false}
tabIndex="0"
type="button"
>
Hello world!
</button>
`;