Skip to content

Commit 29b5a0d

Browse files
authored
fix: Fix ephemeral focus being taken twice (#2521)
## The basics - [x] I [validated my changes](https://developers.google.com/blockly/guides/contribute/samples#making_and_verifying_a_change) ## The details ### Resolves Fixes #2514 Fixes #2515 ### Proposed Changes This updates the custom field implementations for `field-sldier` and `field-angle` to use new functionality introduced in RaspberryPiFoundation/blockly#9051. ### Reason for Changes The regressions reported in #2514 and #2515 were introduced due to the custom fields introducing a scenario where _both_ widget and drop-down divs attempted to take ephemeral focus. This isn't allowed currently as core's `FocusManager` has no tie breaking functionality for ephemeral focus, so the second attempt to request it throws a runtime failure. The functionality introduced in RaspberryPiFoundation/blockly#9051 allows the custom fields to, through `FieldInput`, disable the automatic ephemeral focus management for `FieldInput`'s inline editor (which uses widget div) so that the custom fields' drop-down div editors can properly take focus, instead. ### Test Coverage This has been manually tested locally. Automated tests are, unfortunately, non-trivial here since verifying focus-related behavior (at least through user interactions) requires a working DOM and is very tricky to make work with Node.js. These are tests that would likely be better suited via webdriver, instead. #2527 has been filed to track this work. ### Documentation No additional documentation is needed here. ### Additional Information This requires RaspberryPiFoundation/blockly#9051 in order to work.
1 parent f704ca0 commit 29b5a0d

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

plugins/field-angle/src/field_angle.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,13 @@ export class FieldAngle extends Blockly.FieldNumber {
206206
// eslint-disable-next-line @typescript-eslint/naming-convention
207207
protected override showEditor_(e?: Event) {
208208
// Mobile browsers have issues with in-line textareas (focus & keyboards).
209+
// Also, don't let the parent take ephemeral focus since the drop-down div
210+
// below will handle it, instead.
209211
const noFocus =
210212
Blockly.utils.userAgent.MOBILE ||
211213
Blockly.utils.userAgent.ANDROID ||
212214
Blockly.utils.userAgent.IPAD;
213-
super.showEditor_(e, noFocus);
215+
super.showEditor_(e, noFocus, false);
214216

215217
const editor = this.dropdownCreate();
216218
Blockly.DropDownDiv.getContentDiv().appendChild(editor);

plugins/field-slider/src/field_slider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ export class FieldSlider extends Blockly.FieldNumber {
102102
protected showEditor_(e?: Event, quietInput?: boolean) {
103103
// Always quiet the input for the super constructor, as we don't want to
104104
// focus on the text field, and we don't want to display the modal
105-
// editor on mobile devices.
106-
super.showEditor_(e, true);
105+
// editor on mobile devices. Also, don't let the parent take ephemeral focus
106+
// since the drop-down div below will handle it, instead.
107+
super.showEditor_(e, true, false);
107108

108109
// Build the DOM.
109110
const editor = this.dropdownCreate_();

0 commit comments

Comments
 (0)