Skip to content

Commit

Permalink
chore: rename e to event
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 549039407
  • Loading branch information
AndrewJakubowicz authored and copybara-github committed Jul 18, 2023
1 parent 243e231 commit 10f60d2
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 152 deletions.
6 changes: 3 additions & 3 deletions button/lib/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export abstract class Button extends LitElement {
this.handleSlotChange}"></slot>`;
}

private handleClick(e: MouseEvent) {
private handleClick(event: MouseEvent) {
if (this.isRedispatchingEvent) {
return;
}
Expand All @@ -192,9 +192,9 @@ export abstract class Button extends LitElement {
if (!(isSubmit || isReset)) {
return;
}
e.stopPropagation();
event.stopPropagation();
this.isRedispatchingEvent = true;
const prevented = !redispatchEvent(this, e);
const prevented = !redispatchEvent(this, event);
this.isRedispatchingEvent = false;
if (prevented) {
return;
Expand Down
4 changes: 2 additions & 2 deletions dialog/demo/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export interface StoryKnobs {
supportingText: string;
}

function clickHandler(e: Event) {
((e.target as Element).nextElementSibling as MdDialog)?.show();
function clickHandler(event: Event) {
((event.target as Element).nextElementSibling as MdDialog)?.show();
}


Expand Down
39 changes: 20 additions & 19 deletions dialog/lib/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export class Dialog extends LitElement {
/* Live media query for matching user specified fullscreen breakpoint. */
private fullscreenQuery?: MediaQueryList;
private fullscreenQueryListener:
((e: MediaQueryListEvent) => void)|undefined = undefined;
((event: MediaQueryListEvent) => void)|undefined = undefined;
private updateFullscreen() {
if (this.fullscreenQuery !== undefined) {
this.fullscreenQuery.removeEventListener(
Expand All @@ -462,15 +462,15 @@ export class Dialog extends LitElement {

// handles native close/cancel events and we just ensure
// internal state is in sync.
private handleDialogDismiss(e: Event) {
if (e.type === 'cancel') {
private handleDialogDismiss(event: Event) {
if (event.type === 'cancel') {
this.currentAction = this.escapeKeyAction;
// Prevents the <dialog> element from closing when
// `escapeKeyAction` is set to an empty string.
// It also early returns and avoids <md-dialog> internal state
// changes.
if (this.escapeKeyAction === '') {
e.preventDefault();
event.preventDefault();
return;
}
}
Expand All @@ -479,17 +479,17 @@ export class Dialog extends LitElement {
this.open = false;
this.opening = false;
this.closing = false;
redispatchEvent(this, e);
redispatchEvent(this, event);
}

private handleDialogClick(e: Event) {
private handleDialogClick(event: Event) {
if (!this.open) {
return;
}
this.currentAction =
(e.target as Element).getAttribute(this.actionAttribute) ??
(event.target as Element).getAttribute(this.actionAttribute) ??
(!this.modeless && this.containerElement &&
!e.composedPath().includes(this.containerElement) ?
!event.composedPath().includes(this.containerElement) ?
this.scrimClickAction :
'');
if (this.currentAction !== '') {
Expand Down Expand Up @@ -525,29 +525,30 @@ export class Dialog extends LitElement {
this.getFocusElement()?.blur();
}

private canStartDrag(e: PointerEvent) {
if (this.draggable === false || e.defaultPrevented || !(e.buttons & 1) ||
!this.headerElement || !e.composedPath().includes(this.headerElement)) {
private canStartDrag(event: PointerEvent) {
if (this.draggable === false || event.defaultPrevented ||
!(event.buttons & 1) || !this.headerElement ||
!event.composedPath().includes(this.headerElement)) {
return false;
}
return true;
}

private handlePointerMove(e: PointerEvent) {
if (!this.dragging && !this.canStartDrag(e) || !this.containerElement) {
private handlePointerMove(event: PointerEvent) {
if (!this.dragging && !this.canStartDrag(event) || !this.containerElement) {
return;
}
const {top, left, height, width} =
this.containerElement.getBoundingClientRect();
if (!this.dragging) {
this.containerElement.setPointerCapture(e.pointerId);
this.containerElement.setPointerCapture(event.pointerId);
this.dragging = true;
const {x, y} = e;
const {x, y} = event;
this.dragInfo = [x, y, top, left];
}
const [sx, sy, st, sl] = this.dragInfo ?? [0, 0, 0, 0];
const dx = e.x - sx;
const dy = e.y - sy;
const dx = event.x - sx;
const dy = event.y - sy;
const ml = window.innerWidth - width - this.dragMargin;
const mt = window.innerHeight - height - this.dragMargin;
const l = Math.max(this.dragMargin, Math.min(ml, dx + sl));
Expand All @@ -556,11 +557,11 @@ export class Dialog extends LitElement {
this.style.setProperty('--_container-drag-block-start', `${t}px`);
}

private handleDragEnd(e: PointerEvent) {
private handleDragEnd(event: PointerEvent) {
if (!this.dragging) {
return;
}
this.containerElement?.releasePointerCapture(e.pointerId);
this.containerElement?.releasePointerCapture(event.pointerId);
this.dragging = false;
this.dragInfo = undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions fab/lib/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export abstract class SharedFab extends LitElement {
</span>`;
}

private onSlotchange(e: Event) {
const slotEl = e.target as HTMLSlotElement;
private onSlotchange(event: Event) {
const slotEl = event.target as HTMLSlotElement;
const slottedEls = slotEl.assignedElements({flatten: true});
this.hasIcon = slottedEls.length !== 0;
}
Expand Down
4 changes: 2 additions & 2 deletions labs/navigationdrawer/lib/navigation-drawer-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export class NavigationDrawerModal extends LitElement {
}
}

private handleKeyDown(e: KeyboardEvent) {
if (e.code === 'Escape') {
private handleKeyDown(event: KeyboardEvent) {
if (event.code === 'Escape') {
this.opened = false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions labs/segmentedbuttonset/lib/segmented-button-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export class SegmentedButtonSet extends LitElement {
}
}

private handleSegmentedButtonInteraction(e: CustomEvent) {
const index = this.buttons.indexOf(e.target as SegmentedButton);
private handleSegmentedButtonInteraction(event: CustomEvent) {
const index = this.buttons.indexOf(event.target as SegmentedButton);
this.toggleSelection(index);
}

Expand Down
4 changes: 2 additions & 2 deletions list/lib/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export class List extends LitElement {
* The content to be slotted into the list.
*/
private renderContent() {
return html`<span><slot @click=${(e: Event) => {
e.stopPropagation();
return html`<span><slot @click=${(event: Event) => {
event.stopPropagation();
}}></slot></span>`;
}

Expand Down
9 changes: 5 additions & 4 deletions menu/demo/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,13 @@ const menuWithoutButton: MaterialStoryInit<StoryKnobs> = {
};

function displayCloseEvent(outputRef: Ref<HTMLElement>) {
return (e: CloseMenuEvent) => {
return (event: CloseMenuEvent) => {
if (!outputRef.value) return;

outputRef.value.innerText = `Closed by item(s) with text: ${
JSON.stringify(e.itemPath.map(
item => item.headline))} For reason: ${JSON.stringify(e.reason)}`;
JSON.stringify(event.itemPath.map(
item =>
item.headline))} For reason: ${JSON.stringify(event.reason)}`;
};
}

Expand Down Expand Up @@ -311,7 +312,7 @@ function renderSubMenu(

function renderMenu(
knobs: StoryKnobs, anchorRef: Ref<HTMLElement>, menuRef: Ref<MdMenu>,
onClose: (e: CloseMenuEvent) => void, hasOverflow: boolean,
onClose: (event: CloseMenuEvent) => void, hasOverflow: boolean,
...content: unknown[]) {
return html`
<md-menu
Expand Down
42 changes: 21 additions & 21 deletions menu/lib/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,18 @@ export abstract class Menu extends LitElement {
};
}

private async handleFocusout(e: FocusEvent) {
private async handleFocusout(event: FocusEvent) {
if (this.stayOpenOnFocusout) {
return;
}

// Stop propagation to prevent nested menus from interfering with each other
e.stopPropagation();
event.stopPropagation();

if (e.relatedTarget) {
if (event.relatedTarget) {
// Don't close the menu if we are switching focus between menu,
// md-menu-item, and md-list
if (isElementInSubtree(e.relatedTarget, this)) {
if (isElementInSubtree(event.relatedTarget, this)) {
return;
}
}
Expand All @@ -339,14 +339,14 @@ export abstract class Menu extends LitElement {
// istelf. Specifically useful for the case where typeahead encounters a space
// and we don't want the menu item to close the menu.
@eventOptions({capture: true})
private handleListKeydown(e: KeyboardEvent) {
if (e.target === this.listElement && !e.defaultPrevented &&
isClosableKey(e.code)) {
e.preventDefault();
private handleListKeydown(event: KeyboardEvent) {
if (event.target === this.listElement && !event.defaultPrevented &&
isClosableKey(event.code)) {
event.preventDefault();
this.close();
}

this.typeaheadController.onKeydown(e);
this.typeaheadController.onKeydown(event);
}

/**
Expand Down Expand Up @@ -638,8 +638,8 @@ export abstract class Menu extends LitElement {
}
}

private readonly onWindowClick = (e: MouseEvent) => {
if (!this.stayOpenOnOutsideClick && !e.composedPath().includes(this)) {
private readonly onWindowClick = (event: MouseEvent) => {
if (!this.stayOpenOnOutsideClick && !event.composedPath().includes(this)) {
this.open = false;
}
};
Expand All @@ -648,36 +648,36 @@ export abstract class Menu extends LitElement {
this.close();
}

private onDeactivateItems(e: Event) {
e.stopPropagation();
private onDeactivateItems(event: Event) {
event.stopPropagation();
const items = this.items;
for (const item of items) {
item.active = false;
item.selected = false;
}
}

private handleDeactivateTypeahead(e: DeactivateTypeaheadEvent) {
private handleDeactivateTypeahead(event: DeactivateTypeaheadEvent) {
// stopPropagation so that this does not deactivate any typeaheads in menus
// nested above it e.g. md-sub-menu-item
e.stopPropagation();
event.stopPropagation();
this.typeaheadActive = false;
}

private handleActivateTypeahead(e: ActivateTypeaheadEvent) {
private handleActivateTypeahead(event: ActivateTypeaheadEvent) {
// stopPropagation so that this does not activate any typeaheads in menus
// nested above it e.g. md-sub-menu-item
e.stopPropagation();
event.stopPropagation();
this.typeaheadActive = true;
}

private handleStayOpenOnFocusout(e: Event) {
e.stopPropagation();
private handleStayOpenOnFocusout(event: Event) {
event.stopPropagation();
this.stayOpenOnFocusout = true;
}

private handleCloseOnFocusout(e: Event) {
e.stopPropagation();
private handleCloseOnFocusout(event: Event) {
event.stopPropagation();
this.stayOpenOnFocusout = false;
}

Expand Down
8 changes: 4 additions & 4 deletions menu/lib/menuitem/menu-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export class MenuItemEl extends ListItemEl implements MenuItem {
new DefaultCloseMenuEvent(this, {kind: CLOSE_REASON.CLICK_SELECTION}));
}

protected override onKeydown(e: KeyboardEvent) {
protected override onKeydown(event: KeyboardEvent) {
if (this.keepOpen) return;
const keyCode = e.code;
const keyCode = event.code;

if (!e.defaultPrevented && isClosableKey(keyCode)) {
e.preventDefault();
if (!event.defaultPrevented && isClosableKey(keyCode)) {
event.preventDefault();
this.dispatchEvent(new DefaultCloseMenuEvent(
this, {kind: CLOSE_REASON.KEYDOWN, key: keyCode}));
}
Expand Down
8 changes: 4 additions & 4 deletions menu/lib/menuitemlink/menu-item-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export class MenuItemLink extends ListItemLink implements MenuItem {
new DefaultCloseMenuEvent(this, {kind: CLOSE_REASON.CLICK_SELECTION}));
}

protected override onKeydown(e: KeyboardEvent) {
protected override onKeydown(event: KeyboardEvent) {
if (this.keepOpen) return;

const keyCode = e.code;
const keyCode = event.code;
// Do not preventDefault on enter or else it will prevent from opening links
if (!e.defaultPrevented && isClosableKey(keyCode) &&
if (!event.defaultPrevented && isClosableKey(keyCode) &&
keyCode !== SELECTION_KEY.ENTER) {
e.preventDefault();
event.preventDefault();
this.dispatchEvent(new DefaultCloseMenuEvent(
this, {kind: CLOSE_REASON.KEYDOWN, key: keyCode}));
}
Expand Down
Loading

0 comments on commit 10f60d2

Please sign in to comment.