[7.x] Fix eslint rule for vis_type_metric `jsx-a11y/click-even… (#54363)

This commit is contained in:
Marta Bondyra 2020-01-09 19:10:27 +01:00 committed by GitHub
parent 30932966cb
commit 05d0293374
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View file

@ -94,12 +94,6 @@ module.exports = {
'react-hooks/exhaustive-deps': 'off',
},
},
{
files: ['src/legacy/core_plugins/vis_type_metric/**/*.{js,ts,tsx}'],
rules: {
'jsx-a11y/click-events-have-key-events': 'off',
},
},
{
files: ['src/legacy/core_plugins/vis_type_table/**/*.{js,ts,tsx}'],
rules: {

View file

@ -21,13 +21,19 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { EuiKeyboardAccessible } from '@elastic/eui';
import { EuiKeyboardAccessible, keyCodes } from '@elastic/eui';
class MetricVisValue extends Component {
onClick = () => {
this.props.onFilter(this.props.metric);
};
onKeyPress = e => {
if (e.keyCode === keyCodes.ENTER) {
this.onClick();
}
};
render() {
const { fontSize, metric, onFilter, showLabel } = this.props;
const hasFilter = !!onFilter;
@ -47,6 +53,7 @@ class MetricVisValue extends Component {
className={containerClassName}
style={{ backgroundColor: metric.bgColor }}
onClick={hasFilter ? this.onClick : null}
onKeyPress={hasFilter ? this.onKeyPress : null}
tabIndex={hasFilter ? 0 : null}
role={hasFilter ? 'button' : null}
>