Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
chore: Fixes the disable on the button-group webcomponent and uses Pr…
Browse files Browse the repository at this point in the history
…opertyValue on aria-labeling
  • Loading branch information
rowa-audil authored and lukasholzer committed Sep 23, 2020
1 parent 050c539 commit 044843d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<fluid-button-group
(checkedChange)="handleChange($event)"
[disabled]="disableall"
[disableAll]="disableall"
>
<fluid-button-group-item name="btngrp">
<fluid-button-group-item name="btngrp" [disabled]="disable">
Options 1
</fluid-button-group-item>
<fluid-button-group-item name="btngrp" [disabled]="disable">
<fluid-button-group-item name="btngrp">
Buildingsteps 2
</fluid-button-group-item>
<fluid-button-group-item *ngIf="show" name="btngrp">
Expand Down
8 changes: 4 additions & 4 deletions libs/fluid-elements/button-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ A basic representation of the button-group wrapper for button-group-items

## Properties

| Property | Attribute | Type | Description |
| ----------- | ----------- | ---------------- | ----------------------------------------------------------- |
| `checkedId` | `checkedId` | `string || null` | Currently checked button group item. |
| `disabled` | `disabled` | `boolean` | Whether the component and the children are disabled or not. |
| Property | Attribute | Type | Description |
| ------------ | ----------- | ---------------- | ----------------------------------------------------------- |
| `checkedId` | `checkedId` | `string || null` | Currently checked button group item. |
| `disableAll` | `disabled` | `boolean` | Whether the component and the children are disabled or not. |

## Slots

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ export class FluidButtonGroupItem extends LitElement {
}
:host([disabled]) .fluid-label {
// TODO: Should be replaced by an opacity token at some point.
opacity: 0.5;
}
:host([disabled]) .fluid-button-group-item-svg {
// TODO: Should be replaced by an opacity token at some point.
opacity: 0.5;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ describe('Fluid button-group', () => {
});
});

describe('disabled attribute', () => {
describe('disableAll attribute', () => {
it('should disable every item if attribute is set', async () => {
fixture.setAttribute('disabled', '');
fixture.setAttribute('disableAll', '');
await tick();
expect(
fixture.querySelector<FluidButtonGroupItem>(
Expand All @@ -137,7 +137,7 @@ describe('Fluid button-group', () => {
).toBe(true);
});
it('should disable every item if property is set to true', async () => {
fixture.disabled = true;
fixture.disableAll = true;
await tick();
expect(
fixture.querySelector<FluidButtonGroupItem>(
Expand All @@ -156,7 +156,7 @@ describe('Fluid button-group', () => {
).toBe(true);
});
it('should enable every item if property is reset', async () => {
fixture.disabled = true;
fixture.disableAll = true;
await tick();
expect(
fixture.querySelector<FluidButtonGroupItem>(
Expand All @@ -173,7 +173,7 @@ describe('Fluid button-group', () => {
'fluid-button-group-item:nth-child(3)',
)?.disabled,
).toBe(true);
fixture.disabled = false;
fixture.disableAll = false;
await tick();
expect(
fixture.querySelector<FluidButtonGroupItem>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ export class FluidButtonGroup extends LitElement {
* @type boolean
*/
@property({ type: Boolean, reflect: true })
get disabled(): boolean {
return this._disabled;
get disableAll(): boolean {
return this._disableAll;
}
set disabled(value: boolean) {
set disableAll(value: boolean) {
const oldValue = value;
this._disabled = value;
this.requestUpdate('disabled', oldValue);
this._disableAll = value;
this.requestUpdate('disableAll', oldValue);
this._setDisabledOnEveryItem();
}
private _disabled = false;
private _disableAll = false;

/**
* Role of the radio-group.
Expand Down Expand Up @@ -212,7 +212,7 @@ export class FluidButtonGroup extends LitElement {
/** Disables every item in the group */
private _setDisabledOnEveryItem(): void {
for (const item of this._buttonGroupItems) {
item.disabled = this._disabled;
item.disabled = this._disableAll;
}
}
}
5 changes: 3 additions & 2 deletions libs/fluid-elements/checkbox/src/lib/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
css,
unsafeCSS,
customElement,
PropertyValues,
} from 'lit-element';
import { classMap } from 'lit-html/directives/class-map';
import { SPACE } from '@dynatrace/shared/keycodes';
Expand Down Expand Up @@ -258,13 +259,13 @@ export class FluidCheckbox extends LitElement {
ariaChecked: string = 'false';

/** First updated lifecycle */
firstUpdated(props: Map<string | number | symbol, unknown>): void {
firstUpdated(props: PropertyValues): void {
super.firstUpdated(props);
this._inputElement = this.shadowRoot?.querySelector('input')!;
}

/** Update lifecycle */
update(props: Map<string | number | symbol, unknown>): void {
update(props: PropertyValues): void {
// Aria-checked depends on the value of checked, but is never actually
// set by the litElement reactivity. In the updated lifeCycle
// we need to manually update the ariaChecked attribute here.
Expand Down
5 changes: 3 additions & 2 deletions libs/fluid-elements/switch/src/lib/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
CSSResult,
css,
unsafeCSS,
PropertyValues,
} from 'lit-element';
import { classMap } from 'lit-html/directives/class-map';
import { FluidSwitchChangeEvent } from './switch-events';
Expand Down Expand Up @@ -217,13 +218,13 @@ export class FluidSwitch extends LitElement {
ariaChecked: string = 'false';

/** First updated lifecycle */
firstUpdated(props: Map<string | number | symbol, unknown>): void {
firstUpdated(props: PropertyValues): void {
super.firstUpdated(props);
this._inputElement = this.shadowRoot?.querySelector('input')!;
}

/** Update lifecycle */
update(props: Map<string | number | symbol, unknown>): void {
update(props: PropertyValues): void {
// Aria-checked depends on the value of checked, but is never actually
// set by the litElement reactivity. In the updated lifeCycle
// we need to manually update the ariaChecked attribute here.
Expand Down
3 changes: 2 additions & 1 deletion libs/fluid-elements/tab-group/src/lib/tab/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
css,
unsafeCSS,
customElement,
PropertyValues,
} from 'lit-element';
import { classMap } from 'lit-html/directives/class-map';
import {
Expand Down Expand Up @@ -242,7 +243,7 @@ export class FluidTab extends LitElement {
private _rootElement: HTMLSpanElement;

/** First updated lifecycle */
firstUpdated(props: Map<string | number | symbol, unknown>): void {
firstUpdated(props: PropertyValues): void {
super.firstUpdated(props);
this._rootElement = this.shadowRoot?.querySelector(
'.fluid-tab',
Expand Down

0 comments on commit 044843d

Please sign in to comment.