Skip to content

Commit

Permalink
fix(dialog): fixed a bug where opening dialogs with focused Forge ele…
Browse files Browse the repository at this point in the history
…ments that use the ripple could be misaligned (#457)
  • Loading branch information
DRiFTy17 authored Feb 15, 2024
1 parent e30815f commit f295124
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib/dialog/dialog-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { deepQuerySelectorAll, getActiveElement, getShadowElement, removeElement, toggleClass } from '@tylertech/forge-core';
import { BACKDROP_CONSTANTS, IBackdropComponent } from '../backdrop';
import { CHECKBOX_CONSTANTS } from '../checkbox/checkbox-constants';
import { BaseAdapter, IBaseAdapter } from '../core/base/base-adapter';
import { ICON_BUTTON_CONSTANTS } from '../icon-button/icon-button-constants';
import { RADIO_CONSTANTS } from '../radio/radio-constants';
import { SWITCH_CONSTANTS } from '../switch/switch-constants';
import { IDialogComponent } from './dialog';
import { DialogPositionType, DIALOG_CONSTANTS } from './dialog-constants';

Expand All @@ -24,6 +28,7 @@ export interface IDialogAdapter extends IBaseAdapter {
addRootClass(name: string): void;
setFullscreen(value: boolean): void;
setMoveable(value: boolean): void;
tryLayoutRippleChildren(): void;
setMoveTarget(selector: string): boolean;
setMoveTargetHandler(type: string, listener: (evt: MouseEvent) => void): void;
removeDragTargetHandler(type: string, listener: (evt: MouseEvent) => void): void;
Expand Down Expand Up @@ -152,6 +157,17 @@ export class DialogAdapter extends BaseAdapter<IDialogComponent> implements IDia
toggleClass(this._containerElement, value, DIALOG_CONSTANTS.classes.MOVEABLE);
}

public tryLayoutRippleChildren(): void {
const selectors = [
ICON_BUTTON_CONSTANTS.elementName,
SWITCH_CONSTANTS.elementName,
CHECKBOX_CONSTANTS.elementName,
RADIO_CONSTANTS.elementName
];
const rippleChildren = deepQuerySelectorAll(this._component, selectors.join(':focus-within,')) as Array<HTMLElement & { layout(): void }>;
rippleChildren.filter(el => typeof el.layout === 'function').forEach(el => el.layout());
}

public setMoveTarget(selector: string): boolean {
if (!selector) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/lib/dialog/dialog-foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export class DialogFoundation implements IDialogFoundation {
this._adapter.deregisterTransitionEndHandler(this._transitionEndHandler);
this._adapter.setAnimating(false);
this._adapter.emitHostEvent(DIALOG_CONSTANTS.events.READY);
this._adapter.tryLayoutRippleChildren();

if (this._moveable) {
this._initMoveTarget();
Expand Down

0 comments on commit f295124

Please sign in to comment.