Skip to content

Commit

Permalink
Wait for the cell toolbar items to be rendered the first time before …
Browse files Browse the repository at this point in the history
…looking for overlap (#16291)

* Wait for the toolbar item to be rendered the first time before looking for overlap

* remove useless async

* Update benchmark snapshot
  • Loading branch information
brichet committed May 9, 2024
1 parent a5f9207 commit 3c13610
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions packages/cell-toolbar/src/celltoolbartracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ export class CellToolbarTracker implements IDisposable {
return;
}

// Hide the toolbar by default, to avoid temporary overlapping.
cell.node.classList.add(TOOLBAR_OVERLAP_CLASS);

(cell.inputArea!.layout as PanelLayout).insertWidget(
0,
toolbarWidget
Expand Down Expand Up @@ -276,10 +279,12 @@ export class CellToolbarTracker implements IDisposable {
}

private _updateCellForToolbarOverlap(activeCell: Cell<ICellModel>) {
// When we do change in cell, If we don't wait the browser might not have
// completed the layout update, resulting in the previous width being returned
// using `getBoundingClientRect().width` in later functions.
requestAnimationFrame(() => {
// When we do change in cell, the browser might not have completed the layout
// update if we don't wait, resulting in the previous width being returned
// using `getBoundingClientRect().width` in later functions. This also wait for
// the toolbar to be rendered the first time (on page reload), allowing us to
// retrieve the right widgets width.
requestIdleCallback(() => {
// Remove the "toolbar overlap" class from the cell, rendering the cell's toolbar
const activeCellElement = activeCell.node;
activeCellElement.classList.remove(TOOLBAR_OVERLAP_CLASS);
Expand Down

0 comments on commit 3c13610

Please sign in to comment.