-
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(checkbox): Support checkbox click action config #8521
feat(checkbox): Support checkbox click action config #8521
Conversation
@@ -23,6 +23,24 @@ While the `indeterminate` property of the checkbox is true, it will render as in | |||
regardless of the `checked` value. Any interaction with the checkbox by a user (i.e., clicking) will | |||
remove the indeterminate state. | |||
|
|||
### Click action config | |||
When user clicks on the `mat-checkbox`, the default behavior is toggle `checked` value and set |
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.
Mention that this matches the behavior of the native <input type="checkbox">
?
|
||
// Emit our custom change event if the native input emitted one. | ||
// It is important to only emit it, if the native input triggered one, because | ||
// we don't want to trigger a change event, when the `checked` variable changes for example. | ||
this._emitChangeEvent(); | ||
} else if (!this.disabled && this._clickAction === 'noop') { |
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.
Should this be !== 'noop'
?
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.
This is because the input element's check
is set to true
, indeterminate
set to false
on user click. When the setting is noop
, we will need to reset it to current mat-checkbox
's indeterminate
and checked
.
src/lib/checkbox/checkbox.spec.ts
Outdated
testComponent = fixture.debugElement.componentInstance; | ||
|
||
inputElement = <HTMLInputElement>checkboxNativeElement.querySelector('input'); | ||
labelElement = <HTMLLabelElement>checkboxNativeElement.querySelector('label'); |
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.
Prefer as HTMLElement
(even if the other tests use the other syntax from before we had that rule)
src/lib/checkbox/checkbox.spec.ts
Outdated
labelElement = <HTMLLabelElement>checkboxNativeElement.querySelector('label'); | ||
}); | ||
|
||
it('should not set indeterminate to false on click if noop is set', fakeAsync(() => { |
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.
The beforeEach provides check
, but this test says noop
src/lib/checkbox/checkbox.spec.ts
Outdated
@@ -542,6 +543,88 @@ describe('MatCheckbox', () => { | |||
expect(checkboxNativeElement).not.toMatch(/^mat\-checkbox\-anim/g); | |||
}); | |||
}); | |||
|
|||
describe('click action checked only setting', () => { |
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.
describe(`when MAT_CHECKBOX_CLICK_ACTION is 'check'`, ...
?
src/lib/checkbox/checkbox.spec.ts
Outdated
})); | ||
}); | ||
|
||
describe('click action noop setting', () => { |
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.
describe(`when MAT_CHECKBOX_CLICK_ACTION is 'noop'`, ...
?
expect(checkboxNativeElement.classList).not.toContain('mat-checkbox-checked'); | ||
expect(inputElement.indeterminate).toBe(true); | ||
expect(checkboxNativeElement.classList).toContain('mat-checkbox-indeterminate'); | ||
})); |
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.
Add a test for not toggling checked
when it is using 'noop'
?
Comments addressed. Please take a look. Thanks! |
f525f47
to
3716cd9
Compare
3716cd9
to
e15f6b6
Compare
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.
LGTM
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
No description provided.