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
feat(dialog): Reverse buttons when stacked; allow toggling auto-stack #3573
Merged
+162
−36
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ class MDCDialogFoundation extends MDCFoundation { | |
return /** @type {!MDCDialogAdapter} */ ({ | ||
addClass: (/* className: string */) => {}, | ||
removeClass: (/* className: string */) => {}, | ||
hasClass: (/* className: string */) => {}, | ||
addBodyClass: (/* className: string */) => {}, | ||
removeBodyClass: (/* className: string */) => {}, | ||
eventTargetHasClass: (/* target: !EventTarget, className: string */) => {}, | ||
|
@@ -51,6 +52,7 @@ class MDCDialogFoundation extends MDCFoundation { | |
isContentScrollable: () => {}, | ||
areButtonsStacked: () => {}, | ||
getActionFromEvent: (/* event: !Event */) => {}, | ||
reverseButtons: () => {}, | ||
notifyOpening: () => {}, | ||
notifyOpened: () => {}, | ||
notifyClosing: (/* action: ?string */) => {}, | ||
|
@@ -78,6 +80,18 @@ class MDCDialogFoundation extends MDCFoundation { | |
|
||
/** @private {string} */ | ||
this.scrimClickAction_ = strings.CLOSE_ACTION; | ||
|
||
/** @private {boolean} */ | ||
this.autoStackButtons_ = true; | ||
|
||
/** @private {boolean} */ | ||
this.areButtonsStacked_ = false; | ||
}; | ||
|
||
init() { | ||
if (this.adapter_.hasClass(cssClasses.STACKED)) { | ||
this.setAutoStackButtons(false); | ||
} | ||
}; | ||
|
||
destroy() { | ||
|
@@ -158,6 +172,16 @@ class MDCDialogFoundation extends MDCFoundation { | |
this.scrimClickAction_ = action; | ||
} | ||
|
||
/** @return {boolean} */ | ||
getAutoStackButtons() { | ||
return this.autoStackButtons_; | ||
} | ||
|
||
/** @param {boolean} autoStack */ | ||
setAutoStackButtons(autoStack) { | ||
this.autoStackButtons_ = autoStack; | ||
} | ||
|
||
layout() { | ||
if (this.layoutFrame_) { | ||
cancelAnimationFrame(this.layoutFrame_); | ||
|
@@ -169,17 +193,27 @@ class MDCDialogFoundation extends MDCFoundation { | |
} | ||
|
||
layoutInternal_() { | ||
this.detectStackedButtons_(); | ||
if (this.autoStackButtons_) { | ||
this.detectStackedButtons_(); | ||
} | ||
this.detectScrollableContent_(); | ||
} | ||
|
||
/** @private */ | ||
detectStackedButtons_() { | ||
// Remove the class first to let us measure the buttons' natural positions. | ||
this.adapter_.removeClass(cssClasses.STACKED); | ||
if (this.adapter_.areButtonsStacked()) { | ||
|
||
const areButtonsStacked = this.adapter_.areButtonsStacked(); | ||
|
||
if (areButtonsStacked) { | ||
this.adapter_.addClass(cssClasses.STACKED); | ||
} | ||
|
||
if (areButtonsStacked !== this.areButtonsStacked_) { | ||
this.adapter_.reverseButtons(); | ||
this.areButtonsStacked_ = areButtonsStacked; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assignment can be outside if condition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's outside the if, it's going to assign the value even when it's already the same value. Putting it inside the if makes it only assign the value when it's actually going to do something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but I think we don't have to condition this since it is not toggling as in |
||
} | ||
} | ||
|
||
/** @private */ | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this implemented in foundation? couldn't find logic which detects the existence of --stacked modifier class before auto stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's currently implemented in the component (where you left another comment), but I'm moving it to the foundation.