Skip to content

Commit e5243e9

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Allow switching between singe-option and multiple-option polls (mastodon#10603)
1 parent baa3ecd commit e5243e9

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

  • app/javascript/mastodon/features/compose/components

app/javascript/mastodon/features/compose/components/poll_form.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Option extends React.PureComponent {
2626
isPollMultiple: PropTypes.bool,
2727
onChange: PropTypes.func.isRequired,
2828
onRemove: PropTypes.func.isRequired,
29+
onToggleMultiple: PropTypes.func.isRequired,
2930
intl: PropTypes.object.isRequired,
3031
};
3132

@@ -37,13 +38,24 @@ class Option extends React.PureComponent {
3738
this.props.onRemove(this.props.index);
3839
};
3940

41+
handleToggleMultiple = e => {
42+
this.props.onToggleMultiple();
43+
e.preventDefault();
44+
e.stopPropagation();
45+
};
46+
4047
render () {
4148
const { isPollMultiple, title, index, intl } = this.props;
4249

4350
return (
4451
<li>
4552
<label className='poll__text editable'>
46-
<span className={classNames('poll__input', { checkbox: isPollMultiple })} />
53+
<span
54+
className={classNames('poll__input', { checkbox: isPollMultiple })}
55+
onClick={this.handleToggleMultiple}
56+
role='button'
57+
tabIndex='0'
58+
/>
4759

4860
<input
4961
type='text'
@@ -86,6 +98,10 @@ class PollForm extends ImmutablePureComponent {
8698
this.props.onChangeSettings(e.target.value, this.props.isMultiple);
8799
};
88100

101+
handleToggleMultiple = () => {
102+
this.props.onChangeSettings(this.props.expiresIn, !this.props.isMultiple);
103+
};
104+
89105
render () {
90106
const { options, expiresIn, isMultiple, onChangeOption, onRemoveOption, intl } = this.props;
91107

@@ -96,7 +112,7 @@ class PollForm extends ImmutablePureComponent {
96112
return (
97113
<div className='compose-form__poll-wrapper'>
98114
<ul>
99-
{options.map((title, i) => <Option title={title} key={i} index={i} onChange={onChangeOption} onRemove={onRemoveOption} isPollMultiple={isMultiple} />)}
115+
{options.map((title, i) => <Option title={title} key={i} index={i} onChange={onChangeOption} onRemove={onRemoveOption} isPollMultiple={isMultiple} onToggleMultiple={this.handleToggleMultiple} />)}
100116
</ul>
101117

102118
<div className='poll__footer'>

0 commit comments

Comments
 (0)