-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(chips): Add remove functionality/styling. #2476
Closed
topherfangio
wants to merge
1
commit into
angular:master
from
profoundry-us:team/topher/chips-remove-120
Closed
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,8 @@ | |
.mat-basic-chip { | ||
margin: auto 10px; | ||
} | ||
|
||
md-chip-list input { | ||
width: 150px; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -16,34 +16,90 @@ | |
|
||
// The spec only provides guidance for light-themed chips. When inside of a dark theme, fall back | ||
// to standard background and foreground colors. | ||
$unselected-background: if($is-dark-theme, mat-color($background, card), #e0e0e0); | ||
$unselected-background: if($is-dark-theme, #656565, #e0e0e0); | ||
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. Add a comment for the origin of |
||
$unselected-foreground: if($is-dark-theme, mat-color($foreground, text), $light-foreground); | ||
|
||
$selected-background: if($is-dark-theme, mat-color($background, app-bar), #808080); | ||
$selected-foreground: if($is-dark-theme, mat-color($foreground, text), $light-selected-foreground); | ||
|
||
$focus-color: mat-color($foreground, secondary-text); | ||
|
||
.mat-chip:not(.mat-basic-chip) { | ||
background-color: $unselected-background; | ||
color: $unselected-foreground; | ||
|
||
.mat-chip-focus-border { | ||
pointer-events: none; | ||
} | ||
|
||
&:focus { | ||
outline: none; | ||
border: 2px solid $focus-color; | ||
} | ||
|
||
.mat-chip-remove { | ||
color: $unselected-foreground; | ||
opacity: 0.3; | ||
|
||
&:hover { | ||
opacity: 0.54; | ||
} | ||
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. Any way to generally reduce the nesting in this file? |
||
} | ||
} | ||
|
||
.mat-chip.mat-chip-selected:not(.mat-basic-chip) { | ||
background-color: $selected-background; | ||
color: $selected-foreground; | ||
|
||
.mat-chip-remove { | ||
color: $selected-foreground; | ||
opacity: 0.4; | ||
|
||
&:hover { | ||
opacity: 0.54; | ||
} | ||
} | ||
|
||
&.mat-primary { | ||
background-color: mat-color($primary, 500); | ||
color: mat-contrast($primary, 500); | ||
|
||
.mat-chip-remove { | ||
color: mat-contrast($primary, 500); | ||
opacity: 0.4; | ||
|
||
&:hover { | ||
opacity: 0.54; | ||
} | ||
} | ||
} | ||
|
||
&.mat-accent { | ||
background-color: mat-color($accent, 500); | ||
color: mat-contrast($accent, 500); | ||
|
||
.mat-chip-remove { | ||
color: mat-contrast($accent, 500); | ||
opacity: 0.4; | ||
|
||
&:hover { | ||
opacity: 0.54; | ||
} | ||
} | ||
} | ||
|
||
&.mat-warn { | ||
background-color: mat-color($warn, 500); | ||
color: mat-contrast($warn, 500); | ||
|
||
.mat-chip-remove { | ||
color: mat-contrast($warn, 500); | ||
opacity: 0.4; | ||
|
||
&:hover { | ||
opacity: 0.54; | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import {async, TestBed, ComponentFixture} from '@angular/core/testing'; | ||
import {MdChipsModule} from './index'; | ||
import {Component, DebugElement} from '@angular/core'; | ||
import {MdChipInput, MdChipInputEvent} from './chip-input'; | ||
import {By} from '@angular/platform-browser'; | ||
import {Dir} from '../core/rtl/dir'; | ||
import {FakeKeyboardEvent} from './chip-list.spec'; | ||
import {ENTER, COMMA} from '../core/keyboard/keycodes'; | ||
|
||
describe('MdChipInput', () => { | ||
let fixture: ComponentFixture<any>; | ||
let testChipInput: TestChipInput; | ||
let inputDebugElement: DebugElement; | ||
let inputNativeElement: HTMLElement; | ||
let chipInputDirective: MdChipInput; | ||
|
||
let dir = 'ltr'; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MdChipsModule], | ||
declarations: [TestChipInput], | ||
providers: [{ | ||
provide: Dir, useFactory: () => { | ||
return {value: dir.toLowerCase()}; | ||
} | ||
}] | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
})); | ||
|
||
beforeEach(async(() => { | ||
fixture = TestBed.createComponent(TestChipInput); | ||
testChipInput = fixture.debugElement.componentInstance; | ||
fixture.detectChanges(); | ||
|
||
inputDebugElement = fixture.debugElement.query(By.directive(MdChipInput)); | ||
chipInputDirective = inputDebugElement.injector.get(MdChipInput) as MdChipInput; | ||
inputNativeElement = inputDebugElement.nativeElement; | ||
})); | ||
|
||
describe('basic behavior', () => { | ||
it('emits the (chipAdded) on enter keyup', () => { | ||
let ENTER_EVENT = new FakeKeyboardEvent(ENTER, inputNativeElement) as any; | ||
|
||
spyOn(testChipInput, 'add'); | ||
|
||
chipInputDirective._keydown(ENTER_EVENT); | ||
expect(testChipInput.add).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('[addOnBlur]', () => { | ||
it('allows (chipAdded) when true', () => { | ||
spyOn(testChipInput, 'add'); | ||
|
||
testChipInput.addOnBlur = true; | ||
fixture.detectChanges(); | ||
|
||
chipInputDirective._blur(); | ||
expect(testChipInput.add).toHaveBeenCalled(); | ||
}); | ||
|
||
it('disallows (chipAdded) when false', () => { | ||
spyOn(testChipInput, 'add'); | ||
|
||
testChipInput.addOnBlur = false; | ||
fixture.detectChanges(); | ||
|
||
chipInputDirective._blur(); | ||
expect(testChipInput.add).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('[separatorKeys]', () => { | ||
it('does not emit (chipAdded) when a non-separator key is pressed', () => { | ||
let ENTER_EVENT = new FakeKeyboardEvent(ENTER, inputNativeElement) as any; | ||
spyOn(testChipInput, 'add'); | ||
|
||
testChipInput.separatorKeys = [COMMA]; | ||
fixture.detectChanges(); | ||
|
||
chipInputDirective._keydown(ENTER_EVENT); | ||
expect(testChipInput.add).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('emits (chipAdded) when a custom separator keys is pressed', () => { | ||
let COMMA_EVENT = new FakeKeyboardEvent(COMMA, inputNativeElement) as any; | ||
spyOn(testChipInput, 'add'); | ||
|
||
testChipInput.separatorKeys = [COMMA]; | ||
fixture.detectChanges(); | ||
|
||
chipInputDirective._keydown(COMMA_EVENT); | ||
expect(testChipInput.add).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
template: ` | ||
<md-chip-list> | ||
<input mdChipInput [addOnBlur]="addOnBlur" [separatorKeys]="separatorKeys" | ||
(chipAdded)="add($event)" /> | ||
</md-chip-list> | ||
` | ||
}) | ||
class TestChipInput { | ||
addOnBlur: boolean = false; | ||
separatorKeys: number[] = [ENTER]; | ||
|
||
add(event: MdChipInputEvent) { | ||
} | ||
} |
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.
Using the
md-icon
element directly here feels a little weird to me. Couple of thoughts:x
with css and avoid the need for the icon entirely.md-icon
has its own associatedrole
and aria attributes, which may interfere with the chip'soption
-nessbutton
element (since it's an action), but now I'm thinking that's probably not the case, since a screen-reader user will probably want to see the chip as an atomicoption
.So, what do you think of changing this so that there's two directives:
<md-chip-remove>
, which has its own x icon (potentially drawn with css)[mdChipRemove]
as an attribute that you apply when you want to do your own thing (no styles, only behavior)?