Fixes to the polls UI (#10150)

* Allow unselecting choices in multiple choice polls

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

* Visually differentiate checkboxes and radio buttons
This commit is contained in:
ThibG 2019-03-04 01:54:14 +01:00 committed by Eugen Rochko
parent 1a7de769a3
commit 4ced609497
2 changed files with 17 additions and 8 deletions

View file

@ -60,7 +60,11 @@ class Poll extends ImmutablePureComponent {
if (this.props.poll.get('multiple')) { if (this.props.poll.get('multiple')) {
const tmp = { ...this.state.selected }; const tmp = { ...this.state.selected };
if (tmp[value]) {
delete tmp[value];
} else {
tmp[value] = true; tmp[value] = true;
}
this.setState({ selected: tmp }); this.setState({ selected: tmp });
} else { } else {
const tmp = {}; const tmp = {};
@ -86,7 +90,7 @@ class Poll extends ImmutablePureComponent {
}; };
renderOption (option, optionIndex) { renderOption (option, optionIndex) {
const { poll } = this.props; const { poll, disabled } = this.props;
const percent = (option.get('votes_count') / poll.get('votes_count')) * 100; 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 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 active = !!this.state.selected[`${optionIndex}`];
@ -109,9 +113,10 @@ class Poll extends ImmutablePureComponent {
value={optionIndex} value={optionIndex}
checked={active} checked={active}
onChange={this.handleOptionChange} 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>} {showResults && <span className='poll__number'>{Math.floor(percent)}%</span>}
{option.get('title')} {option.get('title')}

View file

@ -47,9 +47,13 @@
height: 18px; height: 18px;
margin-right: 10px; margin-right: 10px;
top: -1px; top: -1px;
border-radius: 4px; border-radius: 50%;
vertical-align: middle; vertical-align: middle;
&.checkbox {
border-radius: 4px;
}
&.active { &.active {
border-color: $valid-value-color; border-color: $valid-value-color;
background: $valid-value-color; background: $valid-value-color;