Unverified Commit 2896e15e authored by Kyle Keating's avatar Kyle Keating Committed by GitHub

Merge pull request #1785 from hypothesis/excerpt-a11y

Fix a11y for Excerpt
parents e8a82607 67e728b6
...@@ -12,24 +12,20 @@ import { applyTheme } from '../util/theme'; ...@@ -12,24 +12,20 @@ import { applyTheme } from '../util/theme';
* it is expanded or collapsed. * it is expanded or collapsed.
*/ */
function InlineControls({ isCollapsed, setCollapsed, linkStyle = {} }) { function InlineControls({ isCollapsed, setCollapsed, linkStyle = {} }) {
const toggleTitle = isCollapsed
? 'Show the full excerpt'
: 'Show the first few lines only';
const toggleLabel = isCollapsed ? 'More' : 'Less'; const toggleLabel = isCollapsed ? 'More' : 'Less';
return ( return (
<div className="excerpt__inline-controls"> <div className="excerpt__inline-controls">
<span className="excerpt__toggle-link"> <span className="excerpt__toggle-link">
{/* FIXME-A11Y */} <button
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} className="excerpt__toggle-button"
<a
href="#"
onClick={() => setCollapsed(!isCollapsed)} onClick={() => setCollapsed(!isCollapsed)}
title={toggleTitle} aria-label="Toggle to show the full excerpt or first few lines only"
aria-pressed={(!isCollapsed).toString()}
style={linkStyle} style={linkStyle}
> >
{toggleLabel} {toggleLabel}
</a> </button>
</span> </span>
</div> </div>
); );
...@@ -113,9 +109,8 @@ function Excerpt({ ...@@ -113,9 +109,8 @@ function Excerpt({
<div className="excerpt__content" ref={contentElement}> <div className="excerpt__content" ref={contentElement}>
{children} {children}
</div> </div>
{/* FIXME-A11Y */}
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}
<div <div
role="presentation"
onClick={() => setCollapsed(false)} onClick={() => setCollapsed(false)}
className={classnames({ className={classnames({
excerpt__shadow: true, excerpt__shadow: true,
......
...@@ -128,11 +128,26 @@ describe('Excerpt', () => { ...@@ -128,11 +128,26 @@ describe('Excerpt', () => {
it('toggles the expanded state when clicked', () => { it('toggles the expanded state when clicked', () => {
const wrapper = createExcerpt({ inlineControls: true }, TALL_DIV); const wrapper = createExcerpt({ inlineControls: true }, TALL_DIV);
const control = wrapper.find('.excerpt__inline-controls a'); const button = wrapper.find('.excerpt__toggle-button');
assert.equal(getExcerptHeight(wrapper), 40); assert.equal(getExcerptHeight(wrapper), 40);
control.simulate('click'); button.simulate('click');
assert.equal(getExcerptHeight(wrapper), 200); assert.equal(getExcerptHeight(wrapper), 200);
}); });
it("sets button's default state to unpressed", () => {
const wrapper = createExcerpt({ inlineControls: true }, TALL_DIV);
const button = wrapper.find('.excerpt__toggle-button');
assert.equal(button.prop('aria-pressed'), 'false');
assert.equal(button.text(), 'More');
});
it("changes button's state to pressed when clicked", () => {
const wrapper = createExcerpt({ inlineControls: true }, TALL_DIV);
wrapper.find('.excerpt__toggle-button').simulate('click');
const button = wrapper.find('.excerpt__toggle-button');
assert.equal(button.prop('aria-pressed'), 'true');
assert.equal(button.text(), 'Less');
});
}); });
it( it(
......
@use "../../mixins/buttons";
@use "../../variables" as var; @use "../../variables" as var;
// FIXME - Remove the `@at-root` here when SASS modules are used, as local // FIXME - Remove the `@at-root` here when SASS modules are used, as local
...@@ -37,6 +38,11 @@ ...@@ -37,6 +38,11 @@
line-height: var.$normal-line-height; line-height: var.$normal-line-height;
} }
.excerpt__toggle-button {
@include buttons.reset-native-btn-styles;
font-style: italic;
}
.excerpt__toggle-link > a { .excerpt__toggle-link > a {
color: var.$text-color; color: var.$text-color;
font-style: italic; font-style: italic;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment