Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/disco/containers/InstallButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class InstallButton extends React.Component {
}

render() {
const { status, downloadProgress } = this.props;
const { downloadProgress, slug, status } = this.props;

if (!validStates.includes(status)) {
throw new Error('Invalid add-on status');
Expand All @@ -49,17 +49,19 @@ export class InstallButton extends React.Component {
const isDisabled = status === UNKNOWN;
const isDownloading = status === DOWNLOADING;
const switchClasses = `switch ${status}`;
const identifier = `install-button-${slug}`;

return (
<div className={switchClasses} onClick={this.handleClick}
data-download-progress={isDownloading ? downloadProgress : 0}>
<input
id={identifier}
className="visually-hidden"
checked={isInstalled}
disabled={isDisabled}
onChange={this.props.handleChange}
type="checkbox" />
<label>
<label htmlFor={identifier}>
{isDownloading ? <div className="progress"></div> : null}
<span className="visually-hidden">{_('Install')}</span>
</label>
Expand Down
7 changes: 7 additions & 0 deletions src/disco/css/InstallButton.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@import "~disco/css/inc/vars";
@import "~core/css/inc/mixins";

$size: 26px;
$borderSize: 1px;

Expand Down Expand Up @@ -59,6 +62,10 @@ $installStripeColor2: #00C42E;
width: 16px;
}

input:focus + label {
@include focus();
}

input + label {
background: #919191;
border-radius: $size;
Expand Down
9 changes: 9 additions & 0 deletions tests/client/disco/containers/TestInstallButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ describe('<InstallButton />', () => {
assert.ok(!uninstall.called);
});

it('should associate the label and input with id and for attributes', () => {
const button = renderButton({status: UNINSTALLED, slug: 'foo'});
const root = findDOMNode(button);
assert.equal(root.querySelector('input').getAttribute('id'),
'install-button-foo', 'id is set');
assert.equal(root.querySelector('label').getAttribute('for'),
'install-button-foo', 'for attribute matches id');
});

it('should throw on bogus status', () => {
assert.throws(() => {
renderButton({status: 'BOGUS'});
Expand Down