about summary refs log tree commit diff
path: root/app/javascript/mastodon/components/poll.js
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-03-04 01:54:14 +0100
committerEugen Rochko <eugen@zeonfederated.com>2019-03-04 01:54:14 +0100
commit4ced609497bc736cb2b1aec921ba5ca7a23a7f53 (patch)
tree7b4dc92e7ac2c516e0b99a29dd5104735a0474c5 /app/javascript/mastodon/components/poll.js
parent1a7de769a318bbb9c01ec520c2033fffee4e89c3 (diff)
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
Diffstat (limited to 'app/javascript/mastodon/components/poll.js')
-rw-r--r--app/javascript/mastodon/components/poll.js19
1 files changed, 12 insertions, 7 deletions
diff --git a/app/javascript/mastodon/components/poll.js b/app/javascript/mastodon/components/poll.js
index c18ee1505..45ce107aa 100644
--- a/app/javascript/mastodon/components/poll.js
+++ b/app/javascript/mastodon/components/poll.js
@@ -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 = {};
@@ -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')}>
@@ -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')}