Skip to content

Commit 0541ee6

Browse files
fix: update field editing focus outline style (#643)
* Update field editing focus outline style When editing a field, workspace focus outline does not disappear and the field does not show passive focus outline. * chore: comment CSS, remove readded duplicate selector * fix: correct use of focus-within * chore: consistently use focus-within I think this behaves more or less the same but is easier to follow. * chore: remove redundant case --------- Co-authored-by: Grace <[email protected]>
1 parent d5151f2 commit 0541ee6

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

src/index.ts

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,37 +164,64 @@ export class KeyboardNavigation {
164164
//
165165
// This should be moved to core, being integrated into the
166166
// existing styling of renderers in core/renderers/*/constants.ts.
167+
//
168+
// Many selectors include .blocklyKeyboardNavigation to ensure keyboard
169+
// nav is on (via the heuristic). This class is added/removed from body.
167170
Blockly.Css.register(`
168-
/* Blocks, connections and fields. */
171+
/* Active focus cases: */
172+
/* Blocks with active focus. */
169173
.blocklyKeyboardNavigation
170174
.blocklyActiveFocus:is(.blocklyPath, .blocklyHighlightedConnectionPath),
175+
/* Fields with active focus, */
171176
.blocklyKeyboardNavigation
172177
.blocklyActiveFocus.blocklyField
173178
> .blocklyFieldRect,
179+
/* Icons with active focus. */
174180
.blocklyKeyboardNavigation
175181
.blocklyActiveFocus.blocklyIconGroup
176182
> .blocklyIconShape:first-child {
177183
stroke: var(--blockly-active-node-color);
178184
stroke-width: var(--blockly-selection-width);
179185
}
180-
.blocklyKeyboardNavigation
186+
187+
/* Passive focus cases: */
188+
/* Blocks with passive focus except when widget/dropdown div in use. */
189+
.blocklyKeyboardNavigation:not(
190+
:has(
191+
.blocklyDropDownDiv:focus-within,
192+
.blocklyWidgetDiv:focus-within
193+
)
194+
)
181195
.blocklyPassiveFocus:is(
182196
.blocklyPath:not(.blocklyFlyout .blocklyPath),
183197
.blocklyHighlightedConnectionPath
184198
),
185-
.blocklyKeyboardNavigation
199+
/* Fields with passive focus except when widget/dropdown div in use. */
200+
.blocklyKeyboardNavigation:not(
201+
:has(
202+
.blocklyDropDownDiv:focus-within,
203+
.blocklyWidgetDiv:focus-within
204+
)
205+
)
186206
.blocklyPassiveFocus.blocklyField
187207
> .blocklyFieldRect,
188-
.blocklyKeyboardNavigation
208+
/* Icons with passive focus except when widget/dropdown div in use. */
209+
.blocklyKeyboardNavigation:not(
210+
:has(
211+
.blocklyDropDownDiv:focus-within,
212+
.blocklyWidgetDiv:focus-within
213+
)
214+
)
189215
.blocklyPassiveFocus.blocklyIconGroup
190216
> .blocklyIconShape:first-child {
191217
stroke: var(--blockly-active-node-color);
192218
stroke-dasharray: 5px 3px;
193219
stroke-width: var(--blockly-selection-width);
194220
}
221+
222+
/* Workaround for unexpectedly hidden connection path due to core style. */
195223
.blocklyKeyboardNavigation
196224
.blocklyPassiveFocus.blocklyHighlightedConnectionPath {
197-
/* The connection path is being unexpectedly hidden in core */
198225
display: unset !important;
199226
}
200227
`);
@@ -204,14 +231,20 @@ export class KeyboardNavigation {
204231
// This should be moved to core, to core/css.ts if not to somewhere
205232
// more specific in core/toolbox/.
206233
Blockly.Css.register(`
234+
/* Different ways for toolbox/flyout to be the active tree: */
235+
/* Active focus in the flyout. */
207236
.blocklyKeyboardNavigation .blocklyFlyout:has(.blocklyActiveFocus),
237+
/* Active focus in the toolbox. */
208238
.blocklyKeyboardNavigation .blocklyToolbox:has(.blocklyActiveFocus),
239+
/* Active focus on the toolbox/flyout. */
209240
.blocklyKeyboardNavigation
210241
.blocklyActiveFocus:is(.blocklyFlyout, .blocklyToolbox) {
211242
outline-offset: calc(var(--blockly-selection-width) * -1);
212243
outline: var(--blockly-selection-width) solid
213244
var(--blockly-active-tree-color);
214245
}
246+
247+
/* Suppress default outline. */
215248
.blocklyKeyboardNavigation
216249
.blocklyToolboxCategoryContainer:focus-visible {
217250
outline: none;
@@ -222,18 +255,31 @@ export class KeyboardNavigation {
222255
//
223256
// This should be move to core, probably to core/css.ts.
224257
Blockly.Css.register(`
258+
/* Different ways for the workspace to be the active tree: */
259+
/* Active focus within workspace. */
225260
.blocklyKeyboardNavigation
226261
.blocklyWorkspace:has(.blocklyActiveFocus)
227262
.blocklyWorkspaceFocusRing,
263+
/* Active focus within drag layer. */
228264
.blocklyKeyboardNavigation
229265
.blocklySvg:has(~ .blocklyBlockDragSurface .blocklyActiveFocus)
230266
.blocklyWorkspaceFocusRing,
267+
/* Active focus on workspace. */
231268
.blocklyKeyboardNavigation
232269
.blocklyWorkspace.blocklyActiveFocus
270+
.blocklyWorkspaceFocusRing,
271+
/* Focus in widget/dropdown div considered to be in workspace. */
272+
.blocklyKeyboardNavigation:has(
273+
.blocklyWidgetDiv:focus-within,
274+
.blocklyDropDownDiv:focus-within
275+
)
276+
.blocklyWorkspace
233277
.blocklyWorkspaceFocusRing {
234278
stroke: var(--blockly-active-tree-color);
235279
stroke-width: calc(var(--blockly-selection-width) * 2);
236280
}
281+
282+
/* The workspace itself is the active node. */
237283
.blocklyKeyboardNavigation
238284
.blocklyWorkspace.blocklyActiveFocus
239285
.blocklyWorkspaceSelectionRing {

0 commit comments

Comments
 (0)