Commit 527aed43 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Use `LinkButton` in Excerpt

parent 884fc5ca
...@@ -5,6 +5,8 @@ import observeElementSize from '../util/observe-element-size'; ...@@ -5,6 +5,8 @@ import observeElementSize from '../util/observe-element-size';
import { withServices } from '../service-context'; import { withServices } from '../service-context';
import { applyTheme } from '../helpers/theme'; import { applyTheme } from '../helpers/theme';
import { LinkButton } from '../../shared/components/buttons';
/** /**
* @typedef InlineControlsProps * @typedef InlineControlsProps
* @prop {boolean} isCollapsed * @prop {boolean} isCollapsed
...@@ -23,17 +25,18 @@ function InlineControls({ isCollapsed, setCollapsed, linkStyle = {} }) { ...@@ -23,17 +25,18 @@ function InlineControls({ isCollapsed, setCollapsed, linkStyle = {} }) {
return ( return (
<div className="Excerpt__inline-controls"> <div className="Excerpt__inline-controls">
<span className="Excerpt__toggle-link"> <div className="Excerpt__toggle-container">
<button <LinkButton
className="Excerpt__toggle-button" className="InlineLinkButton"
onClick={() => setCollapsed(!isCollapsed)} onClick={() => setCollapsed(!isCollapsed)}
aria-expanded={!isCollapsed} expanded={!isCollapsed}
aria-label="Toggle visibility of full excerpt text" title="Toggle visibility of full excerpt text"
style={linkStyle} style={linkStyle}
variant="dark"
> >
{toggleLabel} {toggleLabel}
</button> </LinkButton>
</span> </div>
</div> </div>
); );
} }
......
...@@ -115,36 +115,48 @@ describe('Excerpt', () => { ...@@ -115,36 +115,48 @@ describe('Excerpt', () => {
}); });
context('when inline controls are enabled', () => { context('when inline controls are enabled', () => {
const getToggleButton = wrapper =>
wrapper.find(
'LinkButton[title="Toggle visibility of full excerpt text"]'
);
it('displays inline controls if collapsed', () => { it('displays inline controls if collapsed', () => {
const wrapper = createExcerpt({ inlineControls: true }, TALL_DIV); const wrapper = createExcerpt({ inlineControls: true }, TALL_DIV);
assert.isTrue(wrapper.exists('.Excerpt__inline-controls')); assert.isTrue(wrapper.exists('InlineControls'));
}); });
it('does not display inline controls if not collapsed', () => { it('does not display inline controls if not collapsed', () => {
const wrapper = createExcerpt({ inlineControls: true }, SHORT_DIV); const wrapper = createExcerpt({ inlineControls: true }, SHORT_DIV);
assert.isFalse(wrapper.exists('.Excerpt__inline-controls')); assert.isFalse(wrapper.exists('InlineControls'));
}); });
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 button = wrapper.find('.Excerpt__toggle-button'); const button = getToggleButton(wrapper);
assert.equal(getExcerptHeight(wrapper), 40); assert.equal(getExcerptHeight(wrapper), 40);
button.simulate('click'); act(() => {
button.props().onClick();
});
wrapper.update();
assert.equal(getExcerptHeight(wrapper), 200); assert.equal(getExcerptHeight(wrapper), 200);
}); });
it("sets button's default state to un-expanded", () => { it("sets button's default state to un-expanded", () => {
const wrapper = createExcerpt({ inlineControls: true }, TALL_DIV); const wrapper = createExcerpt({ inlineControls: true }, TALL_DIV);
const button = wrapper.find('.Excerpt__toggle-button'); const button = getToggleButton(wrapper);
assert.equal(button.prop('aria-expanded'), false); assert.equal(button.prop('expanded'), false);
assert.equal(button.text(), 'More'); assert.equal(button.text(), 'More');
}); });
it("changes button's state to expanded when clicked", () => { it("changes button's state to expanded when clicked", () => {
const wrapper = createExcerpt({ inlineControls: true }, TALL_DIV); const wrapper = createExcerpt({ inlineControls: true }, TALL_DIV);
wrapper.find('.Excerpt__toggle-button').simulate('click'); let button = getToggleButton(wrapper);
const button = wrapper.find('.Excerpt__toggle-button'); act(() => {
assert.equal(button.prop('aria-expanded'), true); button.props().onClick();
});
wrapper.update();
button = getToggleButton(wrapper);
assert.equal(button.prop('expanded'), true);
assert.equal(button.text(), 'Less'); assert.equal(button.text(), 'Less');
}); });
}); });
......
@use "../../mixins/buttons";
@use "../../variables" as var; @use "../../variables" as var;
// the distance by which the shadow indicating a collapsed // the distance by which the shadow indicating a collapsed
...@@ -34,7 +33,9 @@ $expand-duration: 0.15s; ...@@ -34,7 +33,9 @@ $expand-duration: 0.15s;
bottom: 0; bottom: 0;
} }
.Excerpt__toggle-link { // A container for a button with a gradient background; this gives partial
// opacity behind the More/Less button so that it is easier to read
.Excerpt__toggle-container {
padding-left: var.$layout-space; padding-left: var.$layout-space;
// See https://stackoverflow.com/a/56548711/9788954 regarding // See https://stackoverflow.com/a/56548711/9788954 regarding
// rgba(255, 255, 255, 0) used here instead of `transparent` (for Safari) // rgba(255, 255, 255, 0) used here instead of `transparent` (for Safari)
...@@ -45,13 +46,6 @@ $expand-duration: 0.15s; ...@@ -45,13 +46,6 @@ $expand-duration: 0.15s;
); );
} }
// TODO the tap target here is quite small
.Excerpt__toggle-button {
@include buttons.reset-native-btn-styles;
background: transparent;
font-style: italic;
}
// a shadow displayed at the bottom of an <excerpt>s with inline controls // a shadow displayed at the bottom of an <excerpt>s with inline controls
// disabled, which provides a hint that the excerpt is collapsed // disabled, which provides a hint that the excerpt is collapsed
.Excerpt__shadow { .Excerpt__shadow {
......
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