feat(button): add native type#640
Open
lukasmatta wants to merge 1 commit into
Open
Conversation
Coverage report for library
Test suite run success875 tests passing in 31 suites. Report generated by 🧪jest coverage report action from 300f67a |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new nativeType input to CpsButtonComponent so consumers can configure the rendered HTML <button type="..."> (button|submit|reset), with a default of button, and documents/tests the behavior.
Changes:
- Added
nativeType: 'button' | 'submit' | 'reset'input toCpsButtonComponent(default:'button'). - Updated the button template to bind the native
typeattribute tonativeType. - Updated component API JSON and unit tests to cover the new input and ensure it doesn’t affect styling
type.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.ts | Introduces the nativeType input with a default value. |
| projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.html | Binds the rendered <button> type attribute to nativeType. |
| projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.spec.ts | Adds assertions/tests for default and configured nativeType values. |
| projects/composition/src/app/api-data/cps-button.json | Documents nativeType in the generated component API data. |
| <div> | ||
| <button | ||
| type="button" | ||
| [attr.type]="nativeType" |
Collaborator
There was a problem hiding this comment.
let's maybe apply this guard
Comment on lines
+255
to
+282
| describe('nativeType', () => { | ||
| it('should default native type attribute to "button"', () => { | ||
| const button = fixture.nativeElement.querySelector('button'); | ||
| expect(button.getAttribute('type')).toBe('button'); | ||
| }); | ||
|
|
||
| it('should set native type attribute to "submit"', () => { | ||
| fixture.componentRef.setInput('nativeType', 'submit'); | ||
| fixture.detectChanges(); | ||
| const button = fixture.nativeElement.querySelector('button'); | ||
| expect(button.getAttribute('type')).toBe('submit'); | ||
| }); | ||
|
|
||
| it('should set native type attribute to "reset"', () => { | ||
| fixture.componentRef.setInput('nativeType', 'reset'); | ||
| fixture.detectChanges(); | ||
| const button = fixture.nativeElement.querySelector('button'); | ||
| expect(button.getAttribute('type')).toBe('reset'); | ||
| }); | ||
|
|
||
| it('should not affect styling type when nativeType changes', () => { | ||
| fixture.componentRef.setInput('type', 'outlined'); | ||
| fixture.componentRef.setInput('nativeType', 'submit'); | ||
| fixture.detectChanges(); | ||
| expect(component.classesList).toContain('cps-button--outlined'); | ||
| const button = fixture.nativeElement.querySelector('button'); | ||
| expect(button.getAttribute('type')).toBe('submit'); | ||
| }); |
Playwright test resultsDetails
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request adds support for configuring the native HTML
typeattribute of theCpsButtonComponent, allowing it to be set to'button','submit', or'reset'. The default value is'button'. The changes ensure that the new input is documented, properly reflected in the rendered HTML, and thoroughly tested.Component API and Implementation:
@Input() nativeTypeproperty toCpsButtonComponent, defaulting to'button', which controls the native HTMLtypeattribute of the button (projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.ts).typeattribute to the newnativeTypeinput (projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.html).nativeTypeproperty in the component's JSON API data (projects/composition/src/app/api-data/cps-button.json).Testing:
nativeType, its effect on the rendered button, and its independence from the stylingtypeproperty (projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.spec.ts). [1] [2]Release notes: