Skip to content

Commit 00d7745

Browse files
authored
Revert "fix!: Remove the blocklyMenuItemHighlight CSS class and use the hover…" (#8800)
This reverts commit d6125d4.
1 parent fa4fce5 commit 00d7745

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

core/css.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ input[type=number] {
438438
cursor: inherit;
439439
}
440440
441-
.blocklyMenuItem:hover {
441+
/* State: hover. */
442+
.blocklyMenuItemHighlight {
442443
background-color: rgba(0,0,0,.1);
443444
}
444445

core/menu.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,11 @@ export class Menu {
249249
setHighlighted(item: MenuItem | null) {
250250
const currentHighlighted = this.highlightedItem;
251251
if (currentHighlighted) {
252+
currentHighlighted.setHighlighted(false);
252253
this.highlightedItem = null;
253254
}
254255
if (item) {
256+
item.setHighlighted(true);
255257
this.highlightedItem = item;
256258
// Bring the highlighted item into view. This has no effect if the menu is
257259
// not scrollable.

core/menuitem.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// Former goog.module ID: Blockly.MenuItem
1313

1414
import * as aria from './utils/aria.js';
15+
import * as dom from './utils/dom.js';
1516
import * as idGenerator from './utils/idgenerator.js';
1617

1718
/**
@@ -67,6 +68,7 @@ export class MenuItem {
6768
'blocklyMenuItem ' +
6869
(this.enabled ? '' : 'blocklyMenuItemDisabled ') +
6970
(this.checked ? 'blocklyMenuItemSelected ' : '') +
71+
(this.highlight ? 'blocklyMenuItemHighlight ' : '') +
7072
(this.rightToLeft ? 'blocklyMenuItemRtl ' : '');
7173

7274
const content = document.createElement('div');
@@ -175,6 +177,25 @@ export class MenuItem {
175177
this.checked = checked;
176178
}
177179

180+
/**
181+
* Highlights or unhighlights the component.
182+
*
183+
* @param highlight Whether to highlight or unhighlight the component.
184+
* @internal
185+
*/
186+
setHighlighted(highlight: boolean) {
187+
this.highlight = highlight;
188+
const el = this.getElement();
189+
if (el && this.isEnabled()) {
190+
const name = 'blocklyMenuItemHighlight';
191+
if (highlight) {
192+
dom.addClass(el, name);
193+
} else {
194+
dom.removeClass(el, name);
195+
}
196+
}
197+
}
198+
178199
/**
179200
* Returns true if the menu item is enabled, false otherwise.
180201
*

0 commit comments

Comments
 (0)