Skip to content

Commit

Permalink
fix(core/button): apply correct disable state (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielleroux committed Jan 12, 2023
1 parent 9fc4747 commit 11f97cc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/components/button/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
display: inline-block;
height: 2rem;

&[disabled] {
&.button-disabled {
pointer-events: none;
}
}
6 changes: 5 additions & 1 deletion packages/core/src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export class Button {

render() {
return (
<Host>
<Host
class={{
'button-disabled': this.disabled,
}}
>
<button
type={this.type}
class={getButtonClasses(
Expand Down
54 changes: 54 additions & 0 deletions packages/core/src/components/button/test/button.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* SPDX-FileCopyrightText: 2022 Siemens AG
*
* SPDX-License-Identifier: MIT
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import { newSpecPage, SpecPage } from '@stencil/core/testing';
import { Button } from '../button';

describe('ix-button', () => {
let page: SpecPage;

it('should be disabled without value', async () => {
page = await newSpecPage({
components: [Button],
html: '<ix-button disabled>xxx</ix-button>',
});

await page.waitForChanges();

expect(page.doc.querySelector('ix-button').className).toContain(
'button-disabled'
);
});

it('should be disabled with "true"', async () => {
page = await newSpecPage({
components: [Button],
html: '<ix-button disabled="true">xxx</ix-button>',
});

await page.waitForChanges();

expect(page.doc.querySelector('ix-button').className).toContain(
'button-disabled'
);
});

it('should NOT disabled with "false"', async () => {
page = await newSpecPage({
components: [Button],
html: '<ix-button disabled="false">xxx</ix-button>',
});

await page.waitForChanges();

expect(page.doc.querySelector('ix-button').className).not.toContain(
'button-disabled'
);
});
});

0 comments on commit 11f97cc

Please sign in to comment.