Skip to content

feat: Allow conditioned ephemeral access for drop-down & widget divs #9051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

BenHenning
Copy link
Contributor

@BenHenning BenHenning commented May 14, 2025

The basics

The details

Resolves

Needed for fixing google/blockly-samples#2514 and google/blockly-samples#2515.

Proposed Changes

Update FieldInput along with drop-down and widget divs to support disabling the automatic ephemeral focus functionality.

Reason for Changes

As mentioned in google/blockly-samples#2514 (comment) both google/blockly-samples#2514 and google/blockly-samples#2515 were caused by the custom fields leading to both drop-down and widget divs simultaneously taking ephemeral focus (and that's not currently allowed by FocusManager). This change updates both widget and drop-down divs with optional parameters to conditionally disable automatic ephemeral focus so that FieldInput can, in turn, be customized with disabling automatic ephemeral focus for its inline editor. Being able to disable ephemeral focus for FieldInput allows the custom fields' own drop-down divs to take and manage ephemeral focus, instead, avoiding the duplicate scenario that led to the runtime failure.

Note that the drop-down div change in this PR is completely optional, but it's added for consistency and to avoid future scenarios of breakage when trying to use both divs together (as a fix is required in Core without monkeypatching).

It's worth noting that there could be a possibility for a more 'proper' fix in FocusManager by allowing multiple calls to takeEphemeralFocus, but it's unclear exactly how to solve this consistently (which is why it results in a hard failure today). The main issue is that the current focused node can change from underneath the manager (due to DOM focus changes), and the current focused element may also change. It's not clear if the first, last, or some other call to takeEphemeralFocus should take precedent or which node to return focus once ephemeral focus ends (in cases with multiple subsequent calls).

Test Coverage

No new tests were added, though common field cases were tested manually in core's simple playground and in the plugin-specific playgrounds (per the original regressions). The keyboard navigation plugin test environment was also verified to ensure that this didn't alter any existing behavior (it should be a no-op except for the two custom field plugins).

Automated tests would be nice to add for all three classes, perhaps as part of #8915.

Documentation

The code documentation changes here should be sufficient.

Additional Information

These changes are being done directly to ease solving the above samples issues. See google/blockly-samples#2521 for the follow-up fixes to samples.

This unblocks fixes to 2 samples plugins.
Copy link
Contributor Author

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-reviewed changes (mostly a spot check).

@github-actions github-actions bot added PR: feature Adds a feature and removed PR: feature Adds a feature labels May 14, 2025
@BenHenning BenHenning marked this pull request as ready for review May 14, 2025 22:05
@BenHenning BenHenning requested a review from a team as a code owner May 14, 2025 22:05
@BenHenning BenHenning requested a review from cpcallen May 14, 2025 22:05
@github-actions github-actions bot added PR: feature Adds a feature and removed PR: feature Adds a feature labels May 14, 2025
@maribethb maribethb assigned maribethb and unassigned cpcallen May 14, 2025
@maribethb maribethb requested review from maribethb and removed request for cpcallen May 14, 2025 22:08
@BenHenning
Copy link
Contributor Author

BenHenning commented May 14, 2025

Going ahead and merging per google/blockly-samples#2521 (comment) and another double check that PR still fixes the found regressions.

@BenHenning BenHenning merged commit 083329a into google:rc/v12.0.0 May 14, 2025
7 checks passed
@BenHenning BenHenning deleted the allow-conditioned-ephemeral-access-for-drop-down-widget-divs branch May 14, 2025 22:35
BenHenning added a commit to google/blockly-samples that referenced this pull request May 15, 2025
## 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 google/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 google/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 google/blockly#9051 in order to work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: feature Adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants