Commit Graph

9264 Commits

Author SHA1 Message Date
dependabot[bot]
d5e347db44 chore(deps): bump actions/first-interaction from 1 to 2 (#9274)
Bumps [actions/first-interaction](https://github.com/actions/first-interaction) from 1 to 2.
- [Release notes](https://github.com/actions/first-interaction/releases)
- [Commits](https://github.com/actions/first-interaction/compare/v1...v2)

---
updated-dependencies:
- dependency-name: actions/first-interaction
  dependency-version: '2'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-04 10:02:34 -07:00
RoboErikG
9fc0c386b4 Merge pull request #9275 from google/dependabot/npm_and_yarn/develop/concurrently-9.2.0
chore(deps): bump concurrently from 9.1.2 to 9.2.0
2025-08-04 09:00:51 -07:00
RoboErikG
65289dde09 Merge pull request #9270 from google/dependabot/npm_and_yarn/develop/eslint-plugin-jsdoc-52.0.2
chore(deps): bump eslint-plugin-jsdoc from 51.3.1 to 52.0.2
2025-08-04 08:59:56 -07:00
dependabot[bot]
5e48e0db8c chore(deps): bump concurrently from 9.1.2 to 9.2.0
Bumps [concurrently](https://github.com/open-cli-tools/concurrently) from 9.1.2 to 9.2.0.
- [Release notes](https://github.com/open-cli-tools/concurrently/releases)
- [Commits](https://github.com/open-cli-tools/concurrently/compare/v9.1.2...v9.2.0)

---
updated-dependencies:
- dependency-name: concurrently
  dependency-version: 9.2.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-04 13:58:13 +00:00
dependabot[bot]
71256d69a0 chore(deps): bump eslint-plugin-jsdoc from 51.3.1 to 52.0.2
Bumps [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) from 51.3.1 to 52.0.2.
- [Release notes](https://github.com/gajus/eslint-plugin-jsdoc/releases)
- [Changelog](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/.releaserc)
- [Commits](https://github.com/gajus/eslint-plugin-jsdoc/compare/v51.3.1...v52.0.2)

---
updated-dependencies:
- dependency-name: eslint-plugin-jsdoc
  dependency-version: 52.0.2
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-04 12:22:09 +00:00
michaela-mm
d9421892fb fix: Check for existing event group in cleanUp() (#9265) 2025-08-01 11:30:23 -07:00
Aaron Dodson
c037e7d47d fix: Scroll CommentBarButtons into view on selection. (#9259) 2025-07-30 09:48:00 -07:00
Aaron Dodson
8a578f5ce3 fix: Allow overriding VariableModel via options.plugins. (#9257) 2025-07-30 08:58:30 -07:00
Maribeth Moffatt
c661dd1c94 fix: dont save ids when copying blocks and comments (#9255) 2025-07-28 14:35:55 -07:00
Aaron Dodson
c9a8221a2d fix: Fix displaying HTML elements in FieldDropdown. (#9258) 2025-07-28 13:33:52 -07:00
RoboErikG
b44f7bf1b0 Merge pull request #9207 from google/dependabot/npm_and_yarn/develop/blockly/theme-modern-7.0.1
chore(deps): bump @blockly/theme-modern from 6.0.10 to 7.0.1
2025-07-25 10:09:07 -07:00
dependabot[bot]
0de5b17c8a chore(deps): bump @blockly/theme-modern from 6.0.10 to 7.0.1
Bumps [@blockly/theme-modern](https://github.com/google/blockly-samples/tree/HEAD/plugins/theme-modern) from 6.0.10 to 7.0.1.
- [Release notes](https://github.com/google/blockly-samples/releases)
- [Changelog](https://github.com/google/blockly-samples/blob/master/plugins/theme-modern/CHANGELOG.md)
- [Commits](https://github.com/google/blockly-samples/commits/@blockly/theme-modern@7.0.1/plugins/theme-modern)

---
updated-dependencies:
- dependency-name: "@blockly/theme-modern"
  dependency-version: 7.0.1
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-24 16:29:34 +00:00
Maribeth Moffatt
f37e7fede2 chore: fix docs generation script (#9251)
* chore: pin api-documenter to a version that uses markdown tables

* chore: fix docs generation errors

* chore: update patch for api-documenter
2025-07-24 09:28:18 -07:00
Aaron Dodson
3c7add57ee fix: Make non-autoclosing flyouts stay open. (#9245)
* chore: Add tests for toolbox/flyout/focus autoclose behavior.

* fix: Don't force-close non-autoclosing flyouts.
2025-07-18 14:27:49 -07:00
Aaron Dodson
908712e19d fix: Refer to correct replacement method in deprecation warning. (#9237) 2025-07-15 11:06:27 -07:00
RoboErikG
7e47bf440c Merge pull request #9238 from RoboErikG/toolbox-categories-tests
fix: Fix toolbox categories tests
2025-07-14 11:31:45 -07:00
dependabot[bot]
c1c7ddb293 chore(deps): bump chai from 5.2.0 to 5.2.1 (#9235)
Bumps [chai](https://github.com/chaijs/chai) from 5.2.0 to 5.2.1.
- [Release notes](https://github.com/chaijs/chai/releases)
- [Changelog](https://github.com/chaijs/chai/blob/main/History.md)
- [Commits](https://github.com/chaijs/chai/compare/v5.2.0...v5.2.1)

---
updated-dependencies:
- dependency-name: chai
  dependency-version: 5.2.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 11:17:27 -07:00
Aaron Dodson
7479c2b5c7 fix: Fix order of arguments in IVariableMap.createVariable(). (#9231) 2025-07-14 10:22:09 -07:00
dependabot[bot]
ec01df4ada chore(deps): bump @microsoft/api-documenter from 7.26.26 to 7.26.29 (#9234)
Bumps [@microsoft/api-documenter](https://github.com/microsoft/rushstack/tree/HEAD/apps/api-documenter) from 7.26.26 to 7.26.29.
- [Changelog](https://github.com/microsoft/rushstack/blob/main/apps/api-documenter/CHANGELOG.md)
- [Commits](https://github.com/microsoft/rushstack/commits/@microsoft/api-documenter_v7.26.29/apps/api-documenter)

---
updated-dependencies:
- dependency-name: "@microsoft/api-documenter"
  dependency-version: 7.26.29
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 18:11:03 +01:00
Erik Pasternak
55bd1aff79 Enable categories test 2025-07-14 10:09:51 -07:00
Aaron Dodson
9f66f0c596 fix: Fire a VarTypeChange event when changing a variable's type. (#9236) 2025-07-14 09:53:17 -07:00
Aaron Dodson
52634e4dec fix: Focus the first element in flyouts. (#9228)
* fix: Focus the first element in flyouts.

* refactor: Adjust retrieval of flyout elements.
2025-07-14 08:55:13 -07:00
dependabot[bot]
802d3f887d chore(deps): bump google-closure-compiler (#9233)
Bumps [google-closure-compiler](https://github.com/google/closure-compiler-npm) from 20250625.0.0 to 20250709.0.0.
- [Release notes](https://github.com/google/closure-compiler-npm/releases)
- [Commits](https://github.com/google/closure-compiler-npm/compare/v20250625.0.0...v20250709.0.0)

---
updated-dependencies:
- dependency-name: google-closure-compiler
  dependency-version: 20250709.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 08:35:50 -07:00
Erik Pasternak
2c6c2e1a9d fix: Fix toolbox categories tests (Almost)
This fixes the the toolbox categories tests except for dragging out the four
empty statement blocks, which is fixed by https://github.com/google/blockly-samples/pull/2580

Once the latest version of samples is published the toolbox suite can be
re-enabled.
2025-07-11 13:50:22 -07:00
Aaron Dodson
d5f3d15726 feat: Add support for keyboard navigation to/from block comments. (#9227)
* refactor: Update `TextInputBubble` to use `CommentEditor` for text editing.

* feat: Designate `Bubble` as implementing `IFocusableNode`.

* feat: Dismiss focused bubbles on Escape.

* feat: Add support for keyboard navigation to block comments.

* fix: Scroll comment editors rather than zooming the workspace.

* chore: Add param to docstring.
2025-07-11 10:54:19 -07:00
Maribeth Moffatt
60b7ee1325 release: merge master into develop after v12.2.0
release: merge master into develop after v12.2.0
Merge pull request #9225 from google/master
2025-07-09 17:04:12 -07:00
Maribeth Moffatt
c92314d410 release: v12.2.0
release: v12.2.0
Merge pull request #9224 from google/rc/v12.2.0
blockly-v12.2.0
2025-07-09 13:46:31 -07:00
Maribeth Moffatt
fae8b7fd9e release: merge develop into rv/v12.2.0 2025-07-09 13:40:03 -07:00
Ben Henning
5747feef45 fix: Revert drop down and widget div PRs (#9222)
* Revert "fix: Auto-close widget divs on lost focus (#9216)"

This reverts commit bea183d85d.

* Revert "fix: Auto close drop-down divs on lost focus (reapply) (#9213)"

This reverts commit 0e16b0405a.
2025-07-09 12:13:33 -07:00
Ben Henning
bea183d85d fix: Auto-close widget divs on lost focus (#9216)
## The basics

- [x] I [validated my changes](https://developers.google.com/blockly/guides/contribute/core#making_and_verifying_a_change)

## The details
### Resolves

Fixes https://github.com/google/blockly-keyboard-experimentation/issues/563

### Proposed Changes

This expands the functionality introduced in #9213 to also include widget divs.

### Reason for Changes

MakeCode makes use of widget div in several field editors, so the issues described in https://github.com/google/blockly-keyboard-experimentation/issues/563 aren't fully mitigated with #9213 alone.

This PR essentially adds the same support for auto-closing as drop-down divs now have, and enables this functionality by default.

Note the drop-down div change: it was missed in #9123 that the API change for drop-down div's `show` function is actually API-breaking, so this updates that API to be properly backward compatible (and reverts one test change that makes use of it).

The `FocusManager` change actually corrects an implementation issue from #9123: not updating the tracked focus status before calling the callback can result in focus being inadvertently restored if the callback triggers returning focus due to a lost focus situation. This was wrong for drop-down divs, too, but it's harder to notice there because the dismissal of the drop-down div happens on a timer (which means there's sufficient time for `FocusManager`'s state to correct prior to attempting to return from the ephemeral focus state).

Demonstration of fixed behavior (since the inline number editor uses a widget div):

[Screen recording 2025-07-08 2.12.31 PM.webm](https://github.com/user-attachments/assets/7c3c7c3c-224c-48f4-b4af-bde86feecfa8)

### Test Coverage

New widget div tests have been added to verify the new parameter and auto-close functionality.

The `FocusManager` test was updated to account for the new, and correct, behavior around the internal tracked ephemeral focus state.

Note that some `tabindex` state has been clarified and cleaned up in the test index page and `FocusManager`. It's fine (and preferable) for ephemeral-used elements to always be focusable rather than making them dynamically so (which avoids state bleed across test runs which was happening one of the new tests).

https://github.com/google/blockly-keyboard-experimentation/pull/649 includes additional tests for validating widget behaviors.

### Documentation

No new documentation should be needed here--the API documentation changes should be sufficient.

One documentation update was made in `dropdowndiv.ts` that corrects the documentation parameter ordering.

### Additional Information

Nothing further to add.
2025-07-08 16:06:24 -07:00
Maribeth Moffatt
c0489b41e0 feat: add copy api and paste into correct workspace (#9215)
* feat: add copy api and paste into correct workspace

* fix: dont paste into unrendered workspaces

* fix: paste precondition and add test
2025-07-08 16:05:53 -07:00
RoboErikG
89af298918 Merge pull request #9183 from RoboErikG/fix-browser-tests-2025-06
fix: Fix more browser tests
2025-07-08 15:20:41 -07:00
Erik Pasternak
2fba036a8d Add a todo for enabling the toolbox categories tests 2025-07-08 15:17:33 -07:00
Erik Pasternak
1e40641f45 Fix formatting 2025-07-08 14:35:28 -07:00
Erik Pasternak
274891d34e Responses to comments
- Switch to using scrollBoundsIntoView instead of scrolling the flyout
- Use webdriverio Key.Escape instead of the string code for it
2025-07-08 14:27:50 -07:00
Aaron Dodson
fc9164de8f fix: Prevent loss of focus when deleting a workspace comment. (#9200)
* fix: Prevent loss of focus when deleting a workspace comment.

* chore: Add test verifying workspace comment focus behavior on deletion.
2025-07-08 13:50:26 -07:00
dependabot[bot]
8580d763b3 chore(deps): bump google-closure-compiler from 20240317.0.0 to 20250625.0.0 (#9187)
* chore(deps): bump google-closure-compiler

  Bumps [google-closure-compiler](https://github.com/google/closure-compiler-npm) from 20240317.0.0 to 20250625.0.0.
  - [Release notes](https://github.com/google/closure-compiler-npm/releases)
  - [Commits](https://github.com/google/closure-compiler-npm/compare/v20240317.0.0...v20250625.0.0)

  ---
  updated-dependencies:
  - dependency-name: google-closure-compiler
    dependency-version: 20250625.0.0
    dependency-type: direct:development
    update-type: version-update:semver-major
  ...

  Signed-off-by: dependabot[bot] <support@github.com>

* chore(build): Update import of google-closure-compiler

  The packaging of this module changed and so how we import it needs
  to change as well.

* fix(build): Remove no-longer-supported compiler option

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Christopher Allen <cpcallen+git@google.com>
2025-07-08 14:28:57 +01:00
dependabot[bot]
dfcdcc1935 chore(deps): bump @microsoft/api-extractor from 7.48.1 to 7.52.8 (#9208)
Bumps [@microsoft/api-extractor](https://github.com/microsoft/rushstack/tree/HEAD/apps/api-extractor) from 7.48.1 to 7.52.8.
- [Changelog](https://github.com/microsoft/rushstack/blob/main/apps/api-extractor/CHANGELOG.md)
- [Commits](https://github.com/microsoft/rushstack/commits/@microsoft/api-extractor_v7.52.8/apps/api-extractor)

---
updated-dependencies:
- dependency-name: "@microsoft/api-extractor"
  dependency-version: 7.52.8
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-07 15:53:10 -07:00
Ben Henning
0e16b0405a fix: Auto close drop-down divs on lost focus (reapply) (#9213)
## The basics

- [x] I [validated my changes](https://developers.google.com/blockly/guides/contribute/core#making_and_verifying_a_change)

## The details
### Resolves

Fixes https://github.com/google/blockly-keyboard-experimentation/issues/563

### Proposed Changes

This introduces support in `FocusManager` to receive feedback on when an ephemerally focused element entirely loses focus (that is, neither it nor any of its descendants have focus).

This also introduces a behavior change for drop-down divs using the previously mentioned functionality to automatically close themselves when they lose focus for any reason (e.g. clicking outside of the div or tab navigating away from it).

Finally, and **importantly**, this adds a case where ephemeral focus does _not_ automatically return to the previously focused node: when focus is lost to the ephemerally focused element's tree and isn't instead put on another focused node.

### Reason for Changes

Ultimately, focus is probably the best proxy for cases when a drop-down div ought to no longer be open. However, tracking focus only within the scope of the drop-down div utility is rather difficult since a lot of the same problems that `FocusManager` handles also occur here (with regards to both descendants and outside elements receiving focus). It made more sense to expand `FocusManager`'s ephemeral focus support:
- It was easier to implement this `FocusManager` and in a way that's much more robust (since it's leveraging existing event handlers).
- Using `FocusManager` trivialized the solution for drop-down divs.
- There could be other use cases where custom ephemeral focus uses might benefit from knowing when they lose focus.

This new support is enabled by default for all drop-down divs, but can be disabled by callers if they wish to revert to the previous behavior of not auto-closing.

The change for whether to restore ephemeral focus was needed to fix a drawback that arises from the automatic returning of ephemeral focus introduced in this PR: when a user clicks out of an open drop-down menu it will restore focus back to the node that held focus prior to taking ephemeral focus (since it properly hides the drop-down div and restores focus). This creates awkward behavior issues for both mouse and keyboard users:
- For mouse: trying to open a drop-down outside of Blockly will automatically close the drop-down when the Blockly drop-down finishes closing (since focus is stolen back away from the thing the user clicked on).
- For keyboard: tab navigating out of Blockly tries to force focus back to Blockly.

**New in v2 of this PR**: Commit 0363d67c18 is the main one that prevents #9203 from being reintroduced by ensuring that widget div only clears its contents after ephemeral focus has returned. This was missed in the first audit since it wasn't clear that this line, in particular, can cause a div with focus to be removed and thus focus lost: dfd565957b/core/widgetdiv.ts (L156)

### Test Coverage

New tests have been added for both the drop-down div and `FocusManager` components, and have been verified as failing without the new behaviors in place.

There may be other edge cases worth testing for `FocusManager` in particular, but the tests introduced in this PR seem to cover the most important cases.

**New in v2 of this PR**: A test was added to validate that widget div now clears its contents only after ephemeral focus has returned to avoid the desyncing scenario that led to #9203. This test has been verified to fail without the fix. There are also a few new tests being added in the keyboard navigation plugin repository that also validate this behavior at a higher level (see https://github.com/google/blockly-keyboard-experimentation/pull/649).

Demonstration of the new behavior:

[Screen recording 2025-07-01 6.28.37 PM.webm](https://github.com/user-attachments/assets/7af29fed-1ba1-4828-a6cd-65bb94509e72)

### Documentation

No new documentation changes seem needed beyond the code documentation updates.

### Additional Information

It's also possible to change the automatic restoration behavior to be conditional instead of always assuming focus shouldn't be reset if focus leaves the ephemeral element, but that's probably a better change if there's an actual user issue discovered with this approach.

This was originally introduced in #9175 but it was reverted in #9204 due to #9203.
2025-07-07 15:52:38 -07:00
Aaron Dodson
e3d17becbd fix: Improve workspace comment keyboard navigation behavior. (#9211)
* fix: Prevent tabbing into workspace comments.

* fix: Focus workspace comments when navigating to them using the keyboard.
2025-07-07 15:28:54 -07:00
Aaron Dodson
dfd565957b refactor: Ensure that the workspace cursor is never null. (#9210) 2025-07-07 13:55:40 -07:00
dependabot[bot]
97d0e45418 chore(deps): bump eslint-plugin-prettier from 5.5.0 to 5.5.1 (#9206)
Bumps [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) from 5.5.0 to 5.5.1.
- [Release notes](https://github.com/prettier/eslint-plugin-prettier/releases)
- [Changelog](https://github.com/prettier/eslint-plugin-prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/eslint-plugin-prettier/compare/v5.5.0...v5.5.1)

---
updated-dependencies:
- dependency-name: eslint-plugin-prettier
  dependency-version: 5.5.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-07 13:03:55 -07:00
Erik Pasternak
b890e32bf9 Re-enable undo/redo tests now that focus is working 2025-07-07 11:48:55 -07:00
RoboErikG
9828cfab77 Merge branch 'google:develop' into fix-browser-tests-2025-06 2025-07-07 10:57:42 -07:00
dependabot[bot]
7184cb24f2 chore(deps): bump eslint-config-prettier from 10.1.1 to 10.1.5 (#9209)
Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 10.1.1 to 10.1.5.
- [Release notes](https://github.com/prettier/eslint-config-prettier/releases)
- [Changelog](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/eslint-config-prettier/compare/v10.1.1...v10.1.5)

---
updated-dependencies:
- dependency-name: eslint-config-prettier
  dependency-version: 10.1.5
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-07 18:23:25 +01:00
Christopher Allen
b741d78b5b refactor(CSS): move box-sizing to core/css.ts (#9201)
Apply box-sizing to all of Blockly (and thereby obviate the need
to apply it to .blocklyHtmlInput in particular.
2025-07-07 17:54:00 +01:00
Maribeth Moffatt
efb5a2e7f1 fix: check for a drag specifically rather than a gesture for shortcuts (#9194) 2025-07-07 09:49:38 -07:00
Christopher Allen
7ad18f717a Revert "fix: Auto close drop-down divs on lost focus (#9175)" (#9204)
This reverts commit 4c78c1d4a3 / PR #9175.
2025-07-07 09:40:58 -07:00
Ben Henning
4c78c1d4a3 fix: Auto close drop-down divs on lost focus (#9175)
## The basics

- [x] I [validated my changes](https://developers.google.com/blockly/guides/contribute/core#making_and_verifying_a_change)

## The details
### Resolves

Fixes https://github.com/google/blockly-keyboard-experimentation/issues/563

### Proposed Changes

This introduces support in `FocusManager` to receive feedback on when an ephemerally focused element entirely loses focus (that is, neither it nor any of its descendants have focus).

This also introduces a behavior change for drop-down divs using the previously mentioned functionality to automatically close themselves when they lose focus for any reason (e.g. clicking outside of the div or tab navigating away from it).

Finally, and **importantly**, this adds a case where ephemeral focus does _not_ automatically return to the previously focused node: when focus is lost to the ephemerally focused element's tree and isn't instead put on another focused node.

### Reason for Changes

Ultimately, focus is probably the best proxy for cases when a drop-down div ought to no longer be open. However, tracking focus only within the scope of the drop-down div utility is rather difficult since a lot of the same problems that `FocusManager` handles also occur here (with regards to both descendants and outside elements receiving focus). It made more sense to expand `FocusManager`'s ephemeral focus support:
- It was easier to implement this `FocusManager` and in a way that's much more robust (since it's leveraging existing event handlers).
- Using `FocusManager` trivialized the solution for drop-down divs.
- There could be other use cases where custom ephemeral focus uses might benefit from knowing when they lose focus.

This new support is enabled by default for all drop-down divs, but can be disabled by callers if they wish to revert to the previous behavior of not auto-closing.

The change for whether to restore ephemeral focus was needed to fix a drawback that arises from the automatic returning of ephemeral focus introduced in this PR: when a user clicks out of an open drop-down menu it will restore focus back to the node that held focus prior to taking ephemeral focus (since it properly hides the drop-down div and restores focus). This creates awkward behavior issues for both mouse and keyboard users:
- For mouse: trying to open a drop-down outside of Blockly will automatically close the drop-down when the Blockly drop-down finishes closing (since focus is stolen back away from the thing the user clicked on).
- For keyboard: tab navigating out of Blockly tries to force focus back to Blockly.

### Test Coverage

New tests have been added for both the drop-down div and `FocusManager` components, and have been verified as failing without the new behaviors in place.

There may be other edge cases worth testing for `FocusManager` in particular, but the tests introduced in this PR seem to cover the most important cases.

Demonstration of the new behavior:

[Screen recording 2025-07-01 6.28.37 PM.webm](https://github.com/user-attachments/assets/7af29fed-1ba1-4828-a6cd-65bb94509e72)

### Documentation

No new documentation changes seem needed beyond the code documentation updates.

### Additional Information

It's also possible to change the automatic restoration behavior to be conditional instead of always assuming focus shouldn't be reset if focus leaves the ephemeral element, but that's probably a better change if there's an actual user issue discovered with this approach.
2025-07-02 16:11:50 -07:00
Ben Henning
1e37d21f0a fix: Ensure focus changes when tabbing fields (#9173)
## The basics

- [x] I [validated my changes](https://developers.google.com/blockly/guides/contribute/core#making_and_verifying_a_change)

## The details
### Resolves

Fixes https://github.com/google/blockly-keyboard-experimentation/issues/578
Fixes part of #8915

### Proposed Changes

Ensures fields update focus to the next field when tabbing between field editors. The old behavior can be observed in [#578](https://github.com/google/blockly-keyboard-experimentation/issues/578) and the new behavior can be observed here:

[Screen recording 2025-06-25 1.39.28 PM.webm](https://github.com/user-attachments/assets/e00fcb55-5c20-4d5c-81a8-be9049cc0d7e)

### Reason for Changes

Having focus reset back to the original field editor that was opened is an unexpected experience for users. This approach is better.

Note that there are some separate changes added here, as well:
- Connections and fields now check if their block IDs contain their indicator prefixes since this will all-but-guarantee focus breaks for those nodes. This is an excellent example of why #9171 is needed.
- Some minor naming updates for `FieldInput`: it was incorrectly implying that key events are sent for changes to the `input` element used by the field editor, but they are actually `InputEvent`s per https://developer.mozilla.org/en-US/docs/Web/API/Element/input_event.

### Test Coverage

New tests were added for field editing in general (since this seems to be missing), including tabbing support to ensure the fixes originally introduced in #9049.

One new test has been added specifically for verifying that focus updates with tabbing. This has been verified to fail with the fix removed (as have all tabbing tests with the tabbing code from #9049 removed).

Some specific notes for the test changes:
- There's a slight test dependency inversion happening here. `FieldInput` is being tested with a specific `FieldNumber` class via real block loading. This isn't ideal, but it seems fine given the circumstances (otherwise a lot of extra setup would be necessary for the tests).
- The workspace actually needs to be made visible during tests in order for focus to work correctly (though it's reset at the end of each test, but this may cause some flickering while the tests are running).
- It's the case that a bunch of tests were actually setting up blocks incorrectly (i.e. not defining a must-have `id` property which caused some issues with the new field and connection ID validation checks). These tests have been corrected, but it's worth noting that the blocks are likely still technically wrong since they are not conforming to their TypeScript contracts.
- Similar to the previous point, one test was incorrectly setting the first ID to be returned by the ID generator as `undefined` since (presumably due to a copy-and-paste error when the test was introduced) it was referencing a `TEST_BLOCK_ID` property that hadn't been defined for that test suite. This has been corrected as, without it, there are failures due to the new validation checks.
- For the connection database checks, a new ID is generated instead of fixing the block ID to ensure that it's always unique even if called multiple times (otherwise a block ID would need to be piped through from the calling tests, or an invalid situation would need to be introduced where multiple blocks shared an ID; the former seemed unnecessary and the latter seemed nonideal).
- There are distinct Geras/Zelos tests to validate the case where a full-block field should have its parent block, rather than the field itself, focused on tabbing. See this conversation for more context: https://github.com/google/blockly/pull/9173#discussion_r2172921455.

### Documentation

No documentation changes should be needed here.

### Additional Information

Nothing to add.
2025-07-02 16:07:05 -07:00