pleroma/app/soapbox/components/column_back_button.js
marcin mikołajczak 8f53134b5e Minor accessibility improvements
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2021-07-03 12:43:56 +02:00

35 lines
891 B
JavaScript

import React from 'react';
import { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types';
import Icon from 'soapbox/components/icon';
export default class ColumnBackButton extends React.PureComponent {
static contextTypes = {
router: PropTypes.object,
};
handleClick = () => {
if (window.history && window.history.length === 1) {
this.context.router.history.push('/');
} else {
this.context.router.history.goBack();
}
}
handleKeyUp = (e) => {
if (e.key === 'Enter') {
this.handleClick();
}
}
render() {
return (
<button onClick={this.handleClick} onKeyUp={this.handleKeyUp} className='column-back-button'>
<Icon id='chevron-left' className='column-back-button__icon' fixedWidth />
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
</button>
);
}
}