FIX: Poll builder UI issues (#22931)
1. recent css regression related to modal upgrade 2. autofocus and on-enter regressions 3. array related linting issue (reliance on Ember's firstObject/lastObject)
This commit is contained in:
parent
2d4be458a5
commit
407ff39fdf
|
@ -5,7 +5,9 @@ export default class AutoFocusModifier extends Modifier {
|
|||
|
||||
modify(element) {
|
||||
if (!this.didFocus) {
|
||||
element.autofocus = true;
|
||||
element.focus();
|
||||
|
||||
this.didFocus = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,11 +61,14 @@
|
|||
{{/unless}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{#each this.pollOptions as |option|}}
|
||||
{{#each this.pollOptions as |option index|}}
|
||||
<div class="input-group poll-option-value">
|
||||
<Input
|
||||
@value={{option.value}}
|
||||
@enter={{action "addOption" option}}
|
||||
<input
|
||||
type="text"
|
||||
value={{option.value}}
|
||||
{{auto-focus}}
|
||||
{{on "input" (fn this.updateValue option)}}
|
||||
{{on "keydown" (fn this.onInputKeydown index)}}
|
||||
/>
|
||||
{{#if this.canRemoveOption}}
|
||||
<DButton
|
||||
|
@ -81,7 +84,7 @@
|
|||
class="btn-default poll-option-add"
|
||||
@icon="plus"
|
||||
@label="poll.ui_builder.poll_options.add"
|
||||
@action={{action "addOption" this.pollOptions.lastObject}}
|
||||
@action={{fn this.addOption -1}}
|
||||
/>
|
||||
{{#if
|
||||
(and
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { gt, or } from "@ember/object/computed";
|
||||
import Component from "@ember/component";
|
||||
import EmberObject, { action } from "@ember/object";
|
||||
import { next } from "@ember/runloop";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import { observes } from "@ember-decorators/object";
|
||||
import I18n from "I18n";
|
||||
|
@ -322,12 +321,9 @@ export default class PollUiBuilderModal extends Component {
|
|||
|
||||
@action
|
||||
onOptionsTextChange(e) {
|
||||
let idx = 0;
|
||||
this.set(
|
||||
"pollOptions",
|
||||
e.target.value
|
||||
.split("\n")
|
||||
.map((value) => EmberObject.create({ idx: idx++, value }))
|
||||
e.target.value.split("\n").map((value) => EmberObject.create({ value }))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -349,29 +345,30 @@ export default class PollUiBuilderModal extends Component {
|
|||
}
|
||||
|
||||
@action
|
||||
addOption(beforeOption, value, e) {
|
||||
if (value !== "") {
|
||||
const idx = this.pollOptions.indexOf(beforeOption) + 1;
|
||||
const option = EmberObject.create({ value: "" });
|
||||
this.pollOptions.insertAt(idx, option);
|
||||
updateValue(option, event) {
|
||||
option.set("value", event.target.value);
|
||||
}
|
||||
|
||||
let lastOptionIdx = 0;
|
||||
this.pollOptions.forEach((o) => o.set("idx", lastOptionIdx++));
|
||||
@action
|
||||
onInputKeydown(index, event) {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
next(() => {
|
||||
const pollOptions = document.getElementsByClassName("poll-options");
|
||||
if (pollOptions) {
|
||||
const inputs = pollOptions[0].getElementsByTagName("input");
|
||||
if (option.idx < inputs.length) {
|
||||
inputs[option.idx].focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (event.target.value !== "") {
|
||||
this.addOption(index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
addOption(atIndex) {
|
||||
if (atIndex === -1) {
|
||||
atIndex = this.pollOptions.length;
|
||||
}
|
||||
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
const option = EmberObject.create({ value: "" });
|
||||
this.pollOptions.insertAt(atIndex, option);
|
||||
}
|
||||
|
||||
@action
|
||||
|
|
|
@ -67,13 +67,13 @@
|
|||
margin-bottom: 15px;
|
||||
|
||||
.poll-option-value {
|
||||
align-items: center;
|
||||
align-items: flex-start;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 3px;
|
||||
margin-bottom: 0;
|
||||
|
||||
button {
|
||||
margin-left: 3px;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
.poll-ui-builder-modal {
|
||||
.poll-ui-builder.modal {
|
||||
.modal-inner-container {
|
||||
width: 40em; // scale with user font-size
|
||||
max-width: 100vw; // prevent overflow if user font-size is enourmous
|
||||
max-width: 100vw; // prevent overflow if user font-size is enormous
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
|
|
Loading…
Reference in New Issue