Skip to content

Commit 71ccfc8

Browse files
nicoleoliveirajhonyeduardo
authored andcommitted
feat(button): implementa o método que habilita o foco
Implementa o método que habilita o foco no `po-button`. Fixes DTHFUI-1720
1 parent 9593412 commit 71ccfc8

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

projects/ui/src/lib/components/po-button/po-button.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<button
2+
#button
23
class="po-button po-text-ellipsis"
34
type="button"
45
[class.po-button-danger]="type === 'danger'"

projects/ui/src/lib/components/po-button/po-button.component.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,24 @@ describe('PoButtonComponent: ', () => {
130130

131131
});
132132

133+
describe('Methods:', () => {
134+
135+
it('focus: should call `focus` of button', () => {
136+
component.buttonElement = {
137+
nativeElement: {
138+
focus: () => {}
139+
}
140+
};
141+
142+
spyOn(component.buttonElement.nativeElement, 'focus');
143+
144+
component.focus();
145+
146+
expect(component.buttonElement.nativeElement.focus).toHaveBeenCalled();
147+
});
148+
149+
});
150+
133151
describe('Templates: ', () => {
134152

135153
describe('Loading: ', () => {

projects/ui/src/lib/components/po-button/po-button.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, ElementRef, ViewChild } from '@angular/core';
22

33
import { PoButtonBaseComponent } from './po-button-base.component';
44

@@ -27,6 +27,15 @@ import { PoButtonBaseComponent } from './po-button-base.component';
2727
})
2828
export class PoButtonComponent extends PoButtonBaseComponent {
2929

30+
@ViewChild('button', { static: true }) buttonElement: ElementRef;
31+
32+
/**
33+
* Função que atribui foco ao componente.
34+
*/
35+
focus(): void {
36+
this.buttonElement.nativeElement.focus();
37+
}
38+
3039
onClick() {
3140
this.click.emit(null);
3241
}

0 commit comments

Comments
 (0)