Skip to content

Commit 8ce0e7e

Browse files
committed
fix(embed): avoid activating tab blocks on mount
1 parent 08e80cb commit 8ce0e7e

4 files changed

Lines changed: 9 additions & 16 deletions

File tree

packages/embed-ui/src/services/embed-mount.service.spec.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe('EmbedMountService', () => {
174174
expect(focusOwnerService.getFocusOwner()).toMatchObject({ embedId: 'embed-1', childUnitId: 'child-sheet' });
175175
});
176176

177-
it('activates tab sessions and updates host focus contexts', () => {
177+
it('mounts tab sessions without activating them until the child receives focus', () => {
178178
const firstHost = document.createElement('div');
179179
const secondHost = document.createElement('div');
180180
const hosts = [firstHost, secondHost];
@@ -232,26 +232,22 @@ describe('EmbedMountService', () => {
232232
popupPortal.className = 'univer-popup';
233233
document.body.appendChild(popupPortal);
234234

235-
expect(firstHost.dataset.embedRenderScopeActive).toBe('false');
235+
expect(firstHost.dataset.embedRenderScopeActive).toBe('true');
236236
expect(secondHost.dataset.embedRenderScopeActive).toBe('true');
237237
expect(firstHost.getAttribute(EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE)).toBe('tab-1');
238238
expect(firstHost.getAttribute(EMBED_RUNTIME_FOCUS_ROLE_ATTRIBUTE)).toBe('runtime');
239239
expect(interactionBoundaryService.contains('tab-1', firstChildInput)).toBe(true);
240240
expect(focusCoordinator.isChildUnitRuntimeEvent('child-1', firstChildInput)).toBe(true);
241241
expect(focusCoordinator.isChildUnitRuntimeEvent('host-1', firstChildInput)).toBe(false);
242-
expect(firstHost.getAttribute('aria-hidden')).toBe('true');
242+
expect(firstHost.getAttribute('aria-hidden')).toBeNull();
243243
expect(secondHost.getAttribute('aria-hidden')).toBeNull();
244-
expect(instanceService.setCurrentUnitForType).toHaveBeenCalledWith('child-2');
245-
expect(instanceService.focusUnit).toHaveBeenCalledWith('child-2');
246-
expect(contextService.setContextValue).toHaveBeenCalledWith(FOCUSING_UNIT, true);
247-
expect(contextService.setContextValue).toHaveBeenCalledWith(FOCUSING_SHEET, true);
248-
expect(contextService.setContextValue).toHaveBeenCalledWith(FOCUSING_DOC, false);
249-
expect(contextService.setContextValue).toHaveBeenCalledWith(FOCUSING_SLIDE, false);
250-
expect(focusOwnerService.getFocusOwner()).toMatchObject({ embedId: 'tab-2', childUnitId: 'child-2' });
244+
expect(instanceService.setCurrentUnitForType).not.toHaveBeenCalled();
245+
expect(instanceService.focusUnit).not.toHaveBeenCalled();
246+
expect(contextService.setContextValue).not.toHaveBeenCalled();
247+
expect(focusOwnerService.getFocusOwner()).toBeNull();
251248
firstChildInput.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }));
252249
expect(popupPortal.getAttribute(EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE)).toBe('tab-1');
253250
expect(popupPortal.getAttribute(EMBED_RUNTIME_FOCUS_ROLE_ATTRIBUTE)).toBe('child-popup');
254-
firstHost.dispatchEvent(new FocusEvent('focusin', { bubbles: true }));
255251
expect(contextService.setContextValue).toHaveBeenCalledWith(FOCUSING_UNIT, true);
256252
expect(contextService.setContextValue).toHaveBeenCalledWith(FOCUSING_DOC, true);
257253
expect(contextService.setContextValue).toHaveBeenCalledWith(FOCUSING_SHEET, false);

packages/embed-ui/src/services/embed-mount.service.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ export class EmbedMountService {
181181
context: childContext,
182182
};
183183
this._sessions.set(descriptor.embedId, { session, disposables, setActive });
184-
if (layout === 'tab-peer') {
185-
this.activateSession(descriptor.embedId);
186-
} else {
184+
if (layout !== 'tab-peer') {
187185
this._initializeFloatingSessionActiveState(descriptor, layout, setActive);
188186
}
189187
return session;

packages/sheets-ui/src/embed-register.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('sheets embed register', () => {
4545
});
4646

4747
expect(mount).toHaveBeenCalledWith(descriptor);
48-
expect(activateTab).toHaveBeenCalledWith(descriptor);
48+
expect(activateTab).not.toHaveBeenCalled();
4949

5050
disposable?.dispose();
5151

packages/sheets-ui/src/embed-register.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export function createSheetsEmbedRuntimeService(params: {
136136
}
137137

138138
params.mountService.mount(descriptor);
139-
params.activationService.activateTab(descriptor);
140139

141140
return toDisposable(() => {
142141
params.mountService.unmount(embedId);

0 commit comments

Comments
 (0)