-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(chips): Make chip exit on trailing icon click optional #2893
Changes from 6 commits
2a8bf85
1cf765f
3b5dd0b
9063127
deed34e
9517232
05a3002
a3fe155
97939d3
671a794
bb520fb
3eb5c23
e342c57
4e487b8
75220f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,12 +211,13 @@ To use the `MDCChip` and `MDCChipSet` classes, [import](../../docs/importing-js. | |
|
||
Method Signature | Description | ||
--- | --- | ||
`get foundation() => MDCChipFoundation` | Returns the foundation | ||
`isSelected() => boolean` | Proxies to the foundation's `isSelected` method | ||
`beginExit() => void` | Begins the exit animation which leads to removal of the chip | ||
|
||
Property | Value Type | Description | ||
--- | --- | --- | ||
`foundation` | MDCChipFoundation | The foundation | ||
`shouldRemoveOnTrailingIconClick` | Boolean | Proxies to the foundation's `shouldRemoveOnTrailingIconClick`/`setShouldRemoveOnTrailingIconClick` methods | ||
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. Need to add Also, an additional thought: add a sentence here explaining that if this is set to 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. Sounds good, added as a |
||
`ripple` | `MDCRipple` | The `MDCRipple` instance for the root element that `MDCChip` initializes | ||
|
||
#### `MDCChipSet` | ||
|
@@ -276,6 +277,8 @@ Method Signature | Description | |
--- | --- | ||
`isSelected() => boolean` | Returns true if the chip is selected | ||
`setSelected(selected: boolean) => void` | Sets the chip's selected state | ||
`shouldRemoveOnTrailingIconClick() => boolean` | Returns whether a trailing icon click should trigger exit/removal of the chip | ||
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. should this be |
||
`setShouldRemoveOnTrailingIconClick(shouldRemove: boolean) => void` | Sets whether a trailing icon click should trigger exit/removal of the chip | ||
|
||
#### `MDCChipSetFoundation` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,11 @@ class MDCChipFoundation extends MDCFoundation { | |
constructor(adapter) { | ||
super(Object.assign(MDCChipFoundation.defaultAdapter, adapter)); | ||
|
||
/** | ||
* Whether a trailing icon click should immediately trigger exit/removal of the chip. | ||
* @private {boolean} | ||
* */ | ||
this.shouldRemoveOnTrailingIconClick_ = true; | ||
/** @private {function(!Event): undefined} */ | ||
this.interactionHandler_ = (evt) => this.handleInteraction_(evt); | ||
/** @private {function(!Event): undefined} */ | ||
|
@@ -112,6 +117,20 @@ class MDCChipFoundation extends MDCFoundation { | |
} | ||
} | ||
|
||
/** | ||
* @return {boolean} | ||
*/ | ||
shouldRemoveOnTrailingIconClick() { | ||
return this.shouldRemoveOnTrailingIconClick_; | ||
} | ||
|
||
/** | ||
* @param {boolean} shouldRemove | ||
*/ | ||
setShouldRemoveOnTrailingIconClick(shouldRemove) { | ||
this.shouldRemoveOnTrailingIconClick_ = shouldRemove; | ||
} | ||
|
||
/** | ||
* Handles an interaction event on the root element. | ||
* @param {!Event} evt | ||
|
@@ -175,7 +194,10 @@ class MDCChipFoundation extends MDCFoundation { | |
evt.stopPropagation(); | ||
if (evt.type === 'click' || evt.key === 'Enter' || evt.keyCode === 13) { | ||
this.adapter_.notifyTrailingIconInteraction(); | ||
this.adapter_.addClass(cssClasses.CHIP_EXIT); | ||
if (this.shouldRemoveOnTrailingIconClick_) { | ||
// Begins the exit animation which leads to removal of the chip | ||
this.adapter_.addClass(cssClasses.CHIP_EXIT); | ||
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. It occurs to me that this is effectively doing the same thing that 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. I thought about that but realized that's actually more code? 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. It probably is more code ultimately, but in this case the trade-off is avoiding repeating the same logic across modules which risks skew 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.
Use
function
, not=>
(IE 11)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.
argh, nice catch