Skip to content
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

Renovation: Implement default button behavior #11743

Merged
merged 4 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions js/renovation/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,7 @@ export default class Button extends Widget {
@Prop() stylingMode?: string;
@Prop() text?: string;
@Prop() type?: string;
@Prop() focusStateEnabled?: boolean = true;
@Prop() activeStateEnabled?: boolean = true;
@Prop() hoverStateEnabled?: boolean = true;
}
4 changes: 3 additions & 1 deletion js/renovation/dist/button.j.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class Button extends Widget {

_getDefaultOptions() {
return extend(super._getDefaultOptions(), {
focusStateEnabled: true
focusStateEnabled: true,
activeStateEnabled: true,
hoverStateEnabled: true,
});
}
}
Expand Down
15 changes: 13 additions & 2 deletions js/renovation/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default class Widget {
}

@Effect()
clickEffect() {
accessKeyEffect() {
const namespace = 'UIFeedback';
const isFocusable = this.focusStateEnabled && !this.disabled;
const canBeFocusedByKey = isFocusable && this.accessKey;
Expand All @@ -219,7 +219,6 @@ export default class Widget {
e.stopImmediatePropagation();
this._focused = true;
}
this.onClick!(this.clickArgs);
}, { namespace });

return () => dxClick.off(this.widgetRef, { namespace });
Expand Down Expand Up @@ -269,6 +268,18 @@ export default class Widget {
return () => active.off(this.widgetRef, { selector, namespace });
}

@Effect()
clickEffect() {
const namespace = this.name;

dxClick.on(this.widgetRef,
() => this.onClick!(this.clickArgs),
{ namespace }
);

return () => dxClick.off(this.widgetRef, { namespace });
}

@Effect()
keyboardEffect() {
const hasKeyboardEventHandler = !!this.onKeyboardHandled;
Expand Down
13 changes: 13 additions & 0 deletions testing/jest/button.tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ const render = (props = {}) => {

describe('Button', () => {
describe('Props', () => {
describe('onClick', () => {
it('should be clickable with onClick property only', () => {
const clickHandler = jest.fn();
const button = render({ onClick: clickHandler });

expect(clickHandler).toHaveBeenCalledTimes(0);

button.simulate('click');

expect(clickHandler).toHaveBeenCalledTimes(1);
})
});

describe('stylingMode', () => {
it('should use "contained" as a default value', () => {
const button = render();
Expand Down