Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions plugins/field-slider/src/field_slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ export class FieldSlider extends Blockly.FieldNumber {

// Focus on the slider field, unless quietInput is passed.
if (!quietInput) {
(editor.firstChild as HTMLInputElement).focus({
preventScroll: true,
});
// Wait for the dropdown to animate in before attempting to focus the
// slider.
setTimeout(() => {
this.sliderInput?.focus({
preventScroll: true,
});
}, 250);
}
}

Expand All @@ -153,7 +157,27 @@ export class FieldSlider extends Blockly.FieldNumber {
sliderInput.setAttribute('step', `${this.precision_}`);
sliderInput.setAttribute('value', `${this.getValue()}`);
sliderInput.setAttribute('tabindex', '0');
sliderInput.setAttribute('data-untyped-default-value', String(this.value_));
sliderInput.className = 'fieldSlider';
sliderInput.addEventListener('keydown', (e) => {
let handled = false;
if (e.key === 'Enter') {
handled = true;
} else if (e.key === 'Escape') {
this.isBeingEdited_ = false;
this.setValue(
sliderInput.getAttribute('data-untyped-default-value'),
false,
);
handled = true;
}

if (handled) {
Comment thread
gonfunko marked this conversation as resolved.
Blockly.WidgetDiv.hideIfOwner(this);
Blockly.DropDownDiv.hideIfOwner(this);
e.stopPropagation();
}
});
wrapper.appendChild(sliderInput);
this.sliderInput = sliderInput;

Expand Down
Loading