Skip to content

Commit

Permalink
fix(chips): use notifyRemoval and notifyInteraction adapter methods (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Goo authored Sep 24, 2018
1 parent 54224c8 commit ba433ea
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 33 deletions.
131 changes: 131 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions packages/chips/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,20 @@ export class Chip extends Component {
(propertyName) => window.getComputedStyle(this.chipElement_).getPropertyValue(propertyName),
setStyleProperty: (propertyName, value) => this.chipElement_.style.setProperty(propertyName, value),
notifyRemoval: () => this.props.handleRemove(this.props.id),
notifyInteraction: () => this.props.handleSelect(this.props.id),
};
}

onClick = (e) => {
const {onClick, handleSelect, id} = this.props;
const {onClick} = this.props;
onClick(e);
handleSelect(id);
this.foundation_.handleInteraction(e);
}

onKeyDown = (e) => {
const {onKeyDown} = this.props;
onKeyDown(e);
this.foundation_.handleInteraction(e);
}

handleRemoveIconClick = (e) => this.foundation_.handleTrailingIconInteraction(e);
Expand Down Expand Up @@ -140,6 +147,7 @@ export class Chip extends Component {
handleSelect,
handleRemove,
onClick,
onKeyDown,
computeBoundingRect,
initRipple,
unbounded,
Expand All @@ -156,6 +164,7 @@ export class Chip extends Component {
tabIndex='0'
className={this.classes}
onClick={this.onClick}
onKeyDown={this.onKeyDown}
onTransitionEnd={this.handleTransitionEnd}
ref={this.init}
{...otherProps}
Expand All @@ -177,6 +186,7 @@ Chip.propTypes = {
handleSelect: PropTypes.func,
handleRemove: PropTypes.func,
onClick: PropTypes.func,
onKeyDown: PropTypes.func,
initRipple: PropTypes.func,
unbounded: PropTypes.bool,
chipCheckmark: PropTypes.node,
Expand All @@ -190,6 +200,7 @@ Chip.defaultProps = {
className: '',
selected: false,
onClick: () => {},
onKeyDown: () => {},
initRipple: () => {},
handleSelect: () => {},
handleRemove: () => {},
Expand Down
4 changes: 4 additions & 0 deletions packages/chips/ChipSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ export default class ChipSet extends Component {
if (this.props.selectedChipIds.indexOf(id) > -1) {
this.foundation_.select(id);
} else {
// remove deselect when MDC Web issue 3612 is fixed
this.foundation_.deselect(id);
}
});
}

handleSelect = (chipId) => {
const {handleSelect, choice, filter} = this.props;
// update when mdc web issue is fix
// https://github.com/material-components/material-components-web/issues/3613
if (filter || choice) {
this.foundation_.toggleSelect(chipId);
}
Expand All @@ -98,6 +101,7 @@ export default class ChipSet extends Component {
if (input) {
// this should be calling foundation_.handleChipRemoval, but we would
// need to pass evt.detail.chipId
// fix when MDC Web issue 3613 is fixed
this.foundation_.deselect(chipId);
}
handleRemove(chipId);
Expand Down
Loading

0 comments on commit ba433ea

Please sign in to comment.