mirror of
https://github.com/whippyshou/mastodon
synced 2024-12-12 05:38:57 +09:00
4cfc155560
* feat(aria): Add aria-labels to underlabelled tab nav items The drawer tabs which control primary navigation are only labelled by a title which is not available to many screenreaders. Add an aria-label attribute to each link to improve readability with screenreaders. Organize link attributes so link target is first followed by classname. Issue #1349 * feat(aria): Replace abstract aria role of section with region Abstract aria roles such as section should not be used in content. Use non-abstract 'region' aria role instead. That role expects an aria-labelledby attribute with an id. Pass an ID to the column header. Remove the aria-label attribute on the ColumnHeader because the same value is output in plaintext as its child. Issue #1349 * fix(aria): Remove aria-controls attribute until solution is found Columns do not have wrappers, so these icons can't point to a column wrapper which it controls. Instead these icons function as triggers to show or hide individual columns. #1349 * fix(typo): Remove type of aria-labelledby instead of aria-label
83 lines
2.0 KiB
JavaScript
83 lines
2.0 KiB
JavaScript
import ColumnHeader from './column_header';
|
|
import PropTypes from 'prop-types';
|
|
|
|
const easingOutQuint = (x, t, b, c, d) => c*((t=t/d-1)*t*t*t*t + 1) + b;
|
|
|
|
const scrollTop = (node) => {
|
|
const startTime = Date.now();
|
|
const offset = node.scrollTop;
|
|
const targetY = -offset;
|
|
const duration = 1000;
|
|
let interrupt = false;
|
|
|
|
const step = () => {
|
|
const elapsed = Date.now() - startTime;
|
|
const percentage = elapsed / duration;
|
|
|
|
if (percentage > 1 || interrupt) {
|
|
return;
|
|
}
|
|
|
|
node.scrollTop = easingOutQuint(0, elapsed, offset, targetY, duration);
|
|
requestAnimationFrame(step);
|
|
};
|
|
|
|
step();
|
|
|
|
return () => {
|
|
interrupt = true;
|
|
};
|
|
};
|
|
|
|
class Column extends React.PureComponent {
|
|
|
|
constructor (props, context) {
|
|
super(props, context);
|
|
this.handleHeaderClick = this.handleHeaderClick.bind(this);
|
|
this.handleWheel = this.handleWheel.bind(this);
|
|
}
|
|
|
|
handleHeaderClick () {
|
|
const scrollable = ReactDOM.findDOMNode(this).querySelector('.scrollable');
|
|
if (!scrollable) {
|
|
return;
|
|
}
|
|
this._interruptScrollAnimation = scrollTop(scrollable);
|
|
}
|
|
|
|
handleWheel () {
|
|
if (typeof this._interruptScrollAnimation !== 'undefined') {
|
|
this._interruptScrollAnimation();
|
|
}
|
|
}
|
|
|
|
render () {
|
|
const { heading, icon, children, active, hideHeadingOnMobile } = this.props;
|
|
|
|
let columnHeaderId = null
|
|
let header = '';
|
|
|
|
if (heading) {
|
|
columnHeaderId = heading.replace(/ /g, '-')
|
|
header = <ColumnHeader icon={icon} active={active} type={heading} onClick={this.handleHeaderClick} hideOnMobile={hideHeadingOnMobile} columnHeaderId={columnHeaderId}/>;
|
|
}
|
|
return (
|
|
<div role='region' aria-labelledby={columnHeaderId} className='column' onWheel={this.handleWheel}>
|
|
{header}
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
Column.propTypes = {
|
|
heading: PropTypes.string,
|
|
icon: PropTypes.string,
|
|
children: PropTypes.node,
|
|
active: PropTypes.bool,
|
|
hideHeadingOnMobile: PropTypes.bool
|
|
};
|
|
|
|
export default Column;
|