}
}
- handleOptionChange = e => {
- const { target: { value } } = e;
-
+ _toggleOption = value => {
if (this.props.poll.get('multiple')) {
const tmp = { ...this.state.selected };
if (tmp[value]) {
tmp[value] = true;
this.setState({ selected: tmp });
}
+ }
+
+ handleOptionChange = ({ target: { value } }) => {
+ this._toggleOption(value);
};
+ handleOptionKeyPress = (e) => {
+ if (e.key === 'Enter' || e.key === ' ') {
+ this._toggleOption(e.target.getAttribute('data-index'));
+ e.stopPropagation();
+ e.preventDefault();
+ }
+ }
+
handleVote = () => {
if (this.props.disabled) {
return;
disabled={disabled}
/>
- {!showResults && <span className={classNames('poll__input', { checkbox: poll.get('multiple'), active })} />}
+ {!showResults && (
+ <span
+ className={classNames('poll__input', { checkbox: poll.get('multiple'), active })}
+ tabIndex='0'
+ role={poll.get('multiple') ? 'checkbox' : 'radio'}
+ onKeyPress={this.handleOptionKeyPress}
+ aria-checked={active}
+ aria-label={option.get('title')}
+ data-index={optionIndex}
+ />
+ )}
{showResults && <span className='poll__number'>
{!!voted && <Icon id='check' className='poll__vote__mark' title={intl.formatMessage(messages.voted)} />}
{Math.round(percent)}%
add_option: { id: 'compose_form.poll.add_option', defaultMessage: 'Add a choice' },
remove_option: { id: 'compose_form.poll.remove_option', defaultMessage: 'Remove this choice' },
poll_duration: { id: 'compose_form.poll.duration', defaultMessage: 'Poll duration' },
+ switchToMultiple: { id: 'compose_form.poll.switch_to_multiple', defaultMessage: 'Change poll to allow multiple choices' },
+ switchToSingle: { id: 'compose_form.poll.switch_to_single', defaultMessage: 'Change poll to allow for a single choice' },
minutes: { id: 'intervals.full.minutes', defaultMessage: '{number, plural, one {# minute} other {# minutes}}' },
hours: { id: 'intervals.full.hours', defaultMessage: '{number, plural, one {# hour} other {# hours}}' },
days: { id: 'intervals.full.days', defaultMessage: '{number, plural, one {# day} other {# days}}' },
e.stopPropagation();
};
+ handleCheckboxKeypress = e => {
+ if (e.key === 'Enter' || e.key === ' ') {
+ this.handleToggleMultiple(e);
+ }
+ }
+
onSuggestionsClearRequested = () => {
this.props.onClearSuggestions();
}
<span
className={classNames('poll__input', { checkbox: isPollMultiple })}
onClick={this.handleToggleMultiple}
+ onKeyPress={this.handleCheckboxKeypress}
role='button'
tabIndex='0'
+ title={intl.formatMessage(isPollMultiple ? messages.switchToMultiple : messages.switchToSingle)}
+ aria-label={intl.formatMessage(isPollMultiple ? messages.switchToMultiple : messages.switchToSingle)}
/>
<AutosuggestInput