Skip to content

Commit

Permalink
refactor: rename selected -> isSelected
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlj95 committed Nov 27, 2024
1 parent babd22b commit d88edb6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/app/resume-page/chip/chip.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('ChipComponent', () => {
beforeEach(() => {
;[fixture, component] = componentTestSetup(ChipComponent)
fixture.componentRef.setInput('selected', false)
subscription = component.selectedChange
subscription = component.isSelectedChange
.pipe(first())
.subscribe((isSelectedReceived) => (isSelected = isSelectedReceived))
fixture.detectChanges()
Expand Down
14 changes: 7 additions & 7 deletions src/app/resume-page/chip/chip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import { Component, EventEmitter, input, Output } from '@angular/core'
styleUrls: ['./chip.component.scss'],
standalone: true,
host: {
'[class.selected]': 'selected()',
'[class.selectable]': 'selectedChange.observed',
'[attr.role]': "selectedChange.observed ? 'button': undefined",
'[attr.tabindex]': 'selectedChange.observed ? 0 : undefined',
'[class.selected]': 'isSelected()',
'[class.selectable]': 'isSelectedChange.observed',
'[attr.role]': "isSelectedChange.observed ? 'button': undefined",
'[attr.tabindex]': 'isSelectedChange.observed ? 0 : undefined',
'(click)': 'emitToggledSelected()',
'(keydown.enter)': 'emitToggledSelected()',
'(keydown.space)': 'emitToggledSelected()',
},
})
export class ChipComponent {
readonly selected = input<boolean>()
readonly isSelected = input<boolean>()

@Output()
selectedChange = new EventEmitter<boolean>()
isSelectedChange = new EventEmitter<boolean>()

protected emitToggledSelected() {
this.selectedChange.emit(!this.selected())
this.isSelectedChange.emit(!this.isSelected())
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="chips">
@for (content of contents(); track content) {
<app-chip
[selected]="isActive() && content === activeContent()"
(selectedChange)="select(content)"
[isSelected]="isActive() && content === activeContent()"
(isSelectedChange)="select(content)"
>
{{ content.displayName }}
</app-chip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('ChippedContentComponent', () => {
chipElements.forEach((chipElement, index) => {
const content = CONTENTS[index]

expect(getComponentInstance(chipElement, ChipComponent).selected())
expect(getComponentInstance(chipElement, ChipComponent).isSelected())
.withContext(`chip ${index} is unselected`)
.toBeFalse()

Expand Down Expand Up @@ -100,7 +100,7 @@ describe('ChippedContentComponent', () => {

it('should mark the chip as selected', () => {
expect(
getComponentInstance(firstChipElement, ChipComponent).selected(),
getComponentInstance(firstChipElement, ChipComponent).isSelected(),
).toBe(true)
})

Expand All @@ -126,7 +126,7 @@ describe('ChippedContentComponent', () => {

it('should mark the chip as unselected', () => {
expect(
getComponentInstance(firstChipElement, ChipComponent).selected(),
getComponentInstance(firstChipElement, ChipComponent).isSelected(),
).toBeFalse()
})

Expand All @@ -152,11 +152,11 @@ describe('ChippedContentComponent', () => {

it('should mark the previous chip as unselected and just tapped chip as selected', () => {
expect(
getComponentInstance(firstChipElement, ChipComponent).selected(),
getComponentInstance(firstChipElement, ChipComponent).isSelected(),
).toBeFalse()

expect(
getComponentInstance(secondChipElement, ChipComponent).selected(),
getComponentInstance(secondChipElement, ChipComponent).isSelected(),
).toBeTrue()
})

Expand Down

0 comments on commit d88edb6

Please sign in to comment.