Skip to content

Commit

Permalink
Fixes to the polls UI (mastodon#10150)
Browse files Browse the repository at this point in the history
* Allow unselecting choices in multiple choice polls

* Properly disable checkboxes/radio buttons for polls in public pages

* Visually differentiate checkboxes and radio buttons
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent 546047e commit 970a5e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 12 additions & 7 deletions app/javascript/mastodon/components/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ class Poll extends ImmutablePureComponent {

if (this.props.poll.get('multiple')) {
const tmp = { ...this.state.selected };
tmp[value] = true;
if (tmp[value]) {
delete tmp[value];
} else {
tmp[value] = true;
}
this.setState({ selected: tmp });
} else {
const tmp = {};
Expand All @@ -86,11 +90,11 @@ class Poll extends ImmutablePureComponent {
};

renderOption (option, optionIndex) {
const { poll } = this.props;
const percent = (option.get('votes_count') / poll.get('votes_count')) * 100;
const leading = poll.get('options').filterNot(other => other.get('title') === option.get('title')).every(other => option.get('votes_count') > other.get('votes_count'));
const active = !!this.state.selected[`${optionIndex}`];
const showResults = poll.get('voted') || poll.get('expired');
const { poll, disabled } = this.props;
const percent = (option.get('votes_count') / poll.get('votes_count')) * 100;
const leading = poll.get('options').filterNot(other => other.get('title') === option.get('title')).every(other => option.get('votes_count') > other.get('votes_count'));
const active = !!this.state.selected[`${optionIndex}`];
const showResults = poll.get('voted') || poll.get('expired');

return (
<li key={option.get('title')}>
Expand All @@ -109,9 +113,10 @@ class Poll extends ImmutablePureComponent {
value={optionIndex}
checked={active}
onChange={this.handleOptionChange}
disabled={disabled}
/>

{!showResults && <span className={classNames('poll__input', { active })} />}
{!showResults && <span className={classNames('poll__input', { checkbox: poll.get('multiple'), active })} />}
{showResults && <span className='poll__number'>{Math.floor(percent)}%</span>}

{option.get('title')}
Expand Down
6 changes: 5 additions & 1 deletion app/javascript/styles/mastodon/polls.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@
height: 18px;
margin-right: 10px;
top: -1px;
border-radius: 4px;
border-radius: 50%;
vertical-align: middle;

&.checkbox {
border-radius: 4px;
}

&.active {
border-color: $valid-value-color;
background: $valid-value-color;
Expand Down

0 comments on commit 970a5e9

Please sign in to comment.