Browse Source

fix(polls): Disable submit button if no answers have been chosen

master
Vlad Piersec 3 years ago
parent
commit
7f4fb7f447

+ 1
- 0
css/_polls.scss View File

@@ -406,6 +406,7 @@ a.poll-detail-link, a.poll-change-vote-link {
406 406
     &:disabled {
407 407
         background-color: #00225A;
408 408
         color: #858585;
409
+        cursor: default;
409 410
     }
410 411
 
411 412
     & > *:not(:last-child) {

+ 2
- 1
react/features/polls/components/native/PollAnswer.js View File

@@ -5,6 +5,7 @@ import { Switch, Text, View } from 'react-native';
5 5
 import { Button } from 'react-native-paper';
6 6
 
7 7
 import { BUTTON_MODES } from '../../../chat/constants';
8
+import { isSubmitAnswerDisabled } from '../../functions';
8 9
 import AbstractPollAnswer from '../AbstractPollAnswer';
9 10
 import type { AbstractProps } from '../AbstractPollAnswer';
10 11
 
@@ -12,7 +13,6 @@ import { chatStyles, dialogStyles } from './styles';
12 13
 
13 14
 
14 15
 const PollAnswer = (props: AbstractProps) => {
15
-
16 16
     const {
17 17
         checkBoxStates,
18 18
         poll,
@@ -50,6 +50,7 @@ const PollAnswer = (props: AbstractProps) => {
50 50
                 </Button>
51 51
                 <Button
52 52
                     color = '#17a0db'
53
+                    disabled = { isSubmitAnswerDisabled(checkBoxStates) }
53 54
                     mode = { BUTTON_MODES.CONTAINED }
54 55
                     onPress = { submitAnswer }
55 56
                     style = { chatStyles.pollCreateButton } >

+ 3
- 3
react/features/polls/components/web/PollAnswer.js View File

@@ -3,12 +3,11 @@
3 3
 import { Checkbox } from '@atlaskit/checkbox';
4 4
 import React from 'react';
5 5
 
6
+import { isSubmitAnswerDisabled } from '../../functions';
6 7
 import AbstractPollAnswer from '../AbstractPollAnswer';
7 8
 import type { AbstractProps } from '../AbstractPollAnswer';
8 9
 
9
-
10 10
 const PollAnswer = (props: AbstractProps) => {
11
-
12 11
     const {
13 12
         checkBoxStates,
14 13
         poll,
@@ -51,7 +50,8 @@ const PollAnswer = (props: AbstractProps) => {
51 50
                 </button>
52 51
                 <button
53 52
                     aria-label = { t('polls.answer.submit') }
54
-                    className = { 'poll-small-primary-button' }
53
+                    className = 'poll-small-primary-button'
54
+                    disabled = { isSubmitAnswerDisabled(checkBoxStates) }
55 55
                     onClick = { submitAnswer }>
56 56
                     <span>{t('polls.answer.submit')}</span>
57 57
                 </button>

+ 10
- 0
react/features/polls/functions.js View File

@@ -21,3 +21,13 @@ export function getUnreadPollCount(state: Object) {
21 21
 
22 22
     return nbUnreadPolls;
23 23
 }
24
+
25
+/**
26
+ * Determines if the submit poll answer button should be disabled.
27
+ *
28
+ * @param {Array<boolean>} checkBoxStates - The states of the checkboxes.
29
+ * @returns {boolean}
30
+ */
31
+export function isSubmitAnswerDisabled(checkBoxStates: Array<boolean>) {
32
+    return !checkBoxStates.find(checked => checked);
33
+}

Loading…
Cancel
Save