Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat(chips): Add entry chips #2414

Merged
merged 13 commits into from
Apr 6, 2018
Merged

feat(chips): Add entry chips #2414

merged 13 commits into from
Apr 6, 2018

Conversation

bonniezhou
Copy link
Contributor

First PR for #2010.
Add a way for MDCChipSet to add new chips to the DOM and instantiate them. The demo includes an example of hooking it up to a user input.

Note this PR doesn't include any animations.

@codecov-io
Copy link

codecov-io commented Mar 15, 2018

Codecov Report

Merging #2414 into master will decrease coverage by 0.21%.
The diff coverage is 60.86%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2414      +/-   ##
==========================================
- Coverage   98.85%   98.64%   -0.22%     
==========================================
  Files         103      103              
  Lines        4121     4143      +22     
  Branches      516      518       +2     
==========================================
+ Hits         4074     4087      +13     
- Misses         47       56       +9
Impacted Files Coverage Δ
packages/mdc-chips/chip/constants.js 100% <ø> (ø) ⬆️
packages/mdc-chips/chip-set/foundation.js 90.24% <0%> (-9.76%) ⬇️
packages/mdc-chips/chip-set/index.js 87.5% <73.68%> (-12.5%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 66f2464...15eea87. Read the comment docs.

Copy link
Contributor

@williamernest williamernest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue with IE11 on the demo, and a nit on the docs. Otherwise it LGTM.

demos/chips.html Outdated
@@ -55,7 +55,8 @@

<section class="example">
<h2>Entry Chips</h2>
<div class="mdc-chip-set">
Add entry: <input id="entry-chip-set-input">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a button here instead of relying on the keyboard event.
Also, the keyboard event doesn't work in IE11. No console errors, but doesn't add a chip.

Copy link
Contributor Author

@bonniezhou bonniezhou Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the event listeners to the button instead of input. Also renamed the event handler to simply addChip.

Note that this page will be redesigned once entry chips are complete, so the aesthetic of the input is not important at the moment. There's also the possibility of incorporating the input directly within the entry chip set in the future, pending discussion with design.

@@ -192,6 +196,8 @@ Method Signature | Description
`hasClass(className: string) => boolean` | Returns whether the chip set element has the given class
`registerInteractionHandler(evtType, handler) => void` | Registers an event handler on the root element for a given event
`deregisterInteractionHandler(evtType, handler) => void` | Deregisters an event handler on the root element for a given event
`createChip(text: string, leadingIcon: Element, trailingIcon: Element) => Element` | Returns a chip element with the given text, leading icon, and trailing icon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We're putting parameter types on 3/5 entries in this list.

Copy link
Contributor

@williamernest williamernest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding chips doesn't work in IE11.

@bonniezhou
Copy link
Contributor Author

IE11 doesn't support arrow functions....changed them in chips.html

Copy link
Contributor

@acdvorak acdvorak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest renaming 2 methods, but other than that, this LGTM!

demos/chips.html Outdated
@@ -55,7 +55,11 @@

<section class="example">
<h2>Entry Chips</h2>
<div class="mdc-chip-set">
<input id="entry-chip-set-input">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe give this a placeholder="Chip text"?

demos/chips.html Outdated
@@ -231,10 +235,28 @@ <h2>Custom theme</h2>
<script src="/assets/material-components-web.js" async></script>
<script>
demoReady(function() {
var chipSets = document.querySelectorAll('.mdc-chip-set');
var entryChipSet = document.querySelector('.mdc-chip-set--entry');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Use an #id selector (or document.getElementById())

demos/chips.html Outdated
function addChip(evt) {
if ((evt.type === 'click' || evt.key === 'Enter' || evt.keyCode === 13) &&
entryInput.value !== '') {
var leadingIcon = document.querySelector('.mdc-chip__icon--leading').cloneNode(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Use an #id selector (or document.getElementById())


Method Signature | Description
--- | ---
`createChipElement(text: string, leadingIcon: Element, trailingIcon: Element) => Element` | Returns a new chip element with the given text, leading icon, and trailing icon, added to the root chip set element
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this to addChip()? (Then it'll match MDCChipSet)

`deregisterInteractionHandler(evtType, handler) => void` | Deregisters an event handler on the root element for a given event
`registerInteractionHandler(evtType: string, handler: EventListener) => void` | Registers an event handler on the root element for a given event
`deregisterInteractionHandler(evtType: string, handler: EventListener) => void` | Deregisters an event handler on the root element for a given event
`createChip(text: string, leadingIcon: Element, trailingIcon: Element) => Element` | Returns a chip element with the given text, leading icon, and trailing icon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this to createChipElement()?

@bonniezhou bonniezhou merged commit afe5367 into master Apr 6, 2018
@bonniezhou bonniezhou deleted the feat/chips/entry branch April 9, 2018 17:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants