This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
BREAKING CHANGE: - Dialogs do not require a style="visibility:hidden" attribute in html. - registerTransitionEndHandler, deregisterTransitionEndHandler, and isDialog methods must be implemented by the adapter
- Loading branch information
Showing
8 changed files
with
235 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ export default class MDCDialogFoundation extends MDCFoundation { | |
return { | ||
addClass: (/* className: string */) => {}, | ||
removeClass: (/* className: string */) => {}, | ||
setStyle: (/* propertyName: string, value: string */) => {}, | ||
addBodyClass: (/* className: string */) => {}, | ||
removeBodyClass: (/* className: string */) => {}, | ||
eventTargetHasClass: (/* target: EventTarget, className: string */) => /* boolean */ false, | ||
|
@@ -40,16 +39,18 @@ export default class MDCDialogFoundation extends MDCFoundation { | |
deregisterSurfaceInteractionHandler: (/* evt: string, handler: EventListener */) => {}, | ||
registerDocumentKeydownHandler: (/* handler: EventListener */) => {}, | ||
deregisterDocumentKeydownHandler: (/* handler: EventListener */) => {}, | ||
registerTransitionEndHandler: (/* handler: EventListener */) => {}, | ||
This comment has been minimized.
Sorry, something went wrong. |
||
deregisterTransitionEndHandler: (/* handler: EventListener */) => {}, | ||
notifyAccept: () => {}, | ||
notifyCancel: () => {}, | ||
trapFocusOnSurface: () => {}, | ||
untrapFocusOnSurface: () => {}, | ||
isDialog: (/* el: Element */) => /* boolean */ false, | ||
}; | ||
} | ||
|
||
constructor(adapter) { | ||
super(Object.assign(MDCDialogFoundation.defaultAdapter, adapter)); | ||
|
||
this.isOpen_ = false; | ||
this.componentClickHandler_ = () => this.cancel(true); | ||
this.dialogClickHandler_ = (evt) => this.handleDialogClick_(evt); | ||
|
@@ -58,34 +59,43 @@ export default class MDCDialogFoundation extends MDCFoundation { | |
this.cancel(true); | ||
} | ||
}; | ||
} | ||
this.transitionEndHandler_ = (evt) => this.handleTransitionEnd_(evt); | ||
}; | ||
|
||
destroy() { | ||
this.close(); | ||
// Ensure that dialog is cleaned up when destroyed | ||
if (this.isOpen_) { | ||
this.adapter_.deregisterSurfaceInteractionHandler('click', this.dialogClickHandler_); | ||
this.adapter_.deregisterDocumentKeydownHandler(this.documentKeydownHandler_); | ||
this.adapter_.deregisterInteractionHandler('click', this.componentClickHandler_); | ||
this.adapter_.untrapFocusOnSurface(); | ||
this.adapter_.deregisterTransitionEndHandler(this.transitionEndHandler_); | ||
this.adapter_.removeClass(MDCDialogFoundation.cssClasses.ANIMATING); | ||
this.adapter_.removeClass(MDCDialogFoundation.cssClasses.OPEN); | ||
this.enableScroll_(); | ||
This comment has been minimized.
Sorry, something went wrong.
ensecoz
|
||
} | ||
} | ||
|
||
open() { | ||
this.isOpen_ = true; | ||
this.disableScroll_(); | ||
this.adapter_.setStyle('visibility', 'visible'); | ||
this.adapter_.addClass(MDCDialogFoundation.cssClasses.OPEN); | ||
this.adapter_.trapFocusOnSurface(); | ||
|
||
this.adapter_.registerDocumentKeydownHandler(this.documentKeydownHandler_); | ||
this.adapter_.registerSurfaceInteractionHandler('click', this.dialogClickHandler_); | ||
this.adapter_.registerInteractionHandler('click', this.componentClickHandler_); | ||
this.adapter_.registerTransitionEndHandler(this.transitionEndHandler_); | ||
this.adapter_.addClass(MDCDialogFoundation.cssClasses.ANIMATING); | ||
this.adapter_.addClass(MDCDialogFoundation.cssClasses.OPEN); | ||
} | ||
|
||
close() { | ||
this.isOpen_ = false; | ||
this.adapter_.untrapFocusOnSurface(); | ||
this.adapter_.removeClass(MDCDialogFoundation.cssClasses.OPEN); | ||
this.adapter_.setStyle('visibility', 'hidden'); | ||
this.enableScroll_(); | ||
|
||
this.adapter_.deregisterSurfaceInteractionHandler('click', this.dialogClickHandler_); | ||
this.adapter_.deregisterDocumentKeydownHandler(this.documentKeydownHandler_); | ||
this.adapter_.deregisterInteractionHandler('click', this.componentClickHandler_); | ||
this.adapter_.untrapFocusOnSurface(); | ||
this.adapter_.registerTransitionEndHandler(this.transitionEndHandler_); | ||
this.adapter_.addClass(MDCDialogFoundation.cssClasses.ANIMATING); | ||
this.adapter_.removeClass(MDCDialogFoundation.cssClasses.OPEN); | ||
} | ||
|
||
isOpen() { | ||
|
@@ -118,6 +128,18 @@ export default class MDCDialogFoundation extends MDCFoundation { | |
} | ||
} | ||
|
||
handleTransitionEnd_(evt) { | ||
if (this.adapter_.isDialog(evt.target)) { | ||
this.adapter_.deregisterTransitionEndHandler(this.transitionEndHandler_); | ||
this.adapter_.removeClass(MDCDialogFoundation.cssClasses.ANIMATING); | ||
if (this.isOpen_) { | ||
this.adapter_.trapFocusOnSurface(); | ||
} else { | ||
this.enableScroll_(); | ||
}; | ||
}; | ||
}; | ||
|
||
disableScroll_() { | ||
this.adapter_.addBodyClass(cssClasses.SCROLL_LOCK); | ||
} | ||
|
Oops, something went wrong.
does this line should be deregister? @tranrate