Skip to content

Commit 562a6ac

Browse files
authored
refactor: enforce explicit boolean comparisons (#8033)
2 parents 79e12e8 + 7a9d833 commit 562a6ac

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

packages/components/src/components/button/component.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export class KolButtonWc implements InternalButtonAPI, FocusableElement {
121121
const hasExpertSlot = showExpertSlot(this.state._label);
122122
const hasAriaDescription = Boolean(this.state._ariaDescription?.trim()?.length);
123123
const badgeText = this.state._accessKey || this.state._shortKey;
124+
const isDisabled = this.state._disabled === true;
125+
const hideLabel = this.state._hideLabel === true;
124126

125127
return (
126128
<Host>
@@ -131,17 +133,17 @@ export class KolButtonWc implements InternalButtonAPI, FocusableElement {
131133
aria-describedby={hasAriaDescription ? this.internalDescriptionById : undefined}
132134
aria-expanded={mapBoolean2String(this.state._ariaExpanded)}
133135
aria-haspopup={this._ariaHasPopup}
134-
aria-label={this.state._hideLabel && typeof this.state._label === 'string' ? this.state._label : undefined}
136+
aria-label={hideLabel && typeof this.state._label === 'string' ? this.state._label : undefined}
135137
aria-selected={mapStringOrBoolean2String(this.state._ariaSelected)}
136138
class={clsx('kol-button', {
137-
'kol-button--disabled': this.state._disabled === true,
139+
'kol-button--disabled': isDisabled,
138140
[`kol-button--${this.state._buttonVariant as string}`]: this.state._buttonVariant !== 'custom',
139141
[`kol-button--${this.state._linkVariant as string}`]: this.state._linkVariant,
140-
'kol-button--hide-label': this.state._hideLabel === true,
142+
'kol-button--hide-label': hideLabel,
141143
[this.state._customClass as string]:
142144
this.state._buttonVariant === 'custom' && typeof this.state._customClass === 'string' && this.state._customClass.length > 0,
143145
})}
144-
disabled={this.state._disabled}
146+
disabled={isDisabled}
145147
id={this.state._id}
146148
name={this.state._name}
147149
onClick={this.onClick}
@@ -154,7 +156,7 @@ export class KolButtonWc implements InternalButtonAPI, FocusableElement {
154156
class="kol-button__text"
155157
badgeText={badgeText}
156158
icons={this.state._icons}
157-
hideLabel={this.state._hideLabel}
159+
hideLabel={hideLabel}
158160
label={hasExpertSlot ? '' : this.state._label}
159161
>
160162
<slot name="expert" slot="expert"></slot>
@@ -167,7 +169,7 @@ export class KolButtonWc implements InternalButtonAPI, FocusableElement {
167169
* verhindert aber nicht das Aria-Labelledby vorgelesen wird.
168170
*/
169171
aria-hidden="true"
170-
hidden={hasExpertSlot || !this.state._hideLabel}
172+
hidden={hasExpertSlot || !hideLabel}
171173
class="kol-button__tooltip"
172174
_badgeText={badgeText}
173175
_align={this.state._tooltipAlign}

packages/components/src/components/combobox/shadow.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ export class KolCombobox implements ComboboxAPI {
6161
}
6262

6363
private toggleListbox = () => {
64-
if (this.state._disabled === true) {
64+
const isDisabled = this.state._disabled === true;
65+
if (isDisabled) {
6566
this._isOpen = false;
6667
} else {
6768
this.refInput?.focus();
@@ -173,6 +174,7 @@ export class KolCombobox implements ComboboxAPI {
173174

174175
private getInputProps(): InputStateWrapperProps {
175176
const { ariaDescribedBy } = getRenderStates(this.state);
177+
const isDisabled = this.state._disabled === true;
176178

177179
return {
178180
ref: this.catchRef,
@@ -191,7 +193,7 @@ export class KolCombobox implements ComboboxAPI {
191193
accessKey: this.state._accessKey,
192194
autocapitalize: 'off',
193195
autocorrect: 'off',
194-
disabled: this.state._disabled,
196+
disabled: isDisabled,
195197
customSuggestions: true,
196198
id: this.state._id,
197199
name: this.state._name,
@@ -212,15 +214,16 @@ export class KolCombobox implements ComboboxAPI {
212214
}
213215

214216
public render(): JSX.Element {
217+
const isDisabled = this.state._disabled === true;
215218
return (
216219
<KolFormFieldStateWrapperFc {...this.getFormFieldProps()}>
217220
<KolInputContainerFc state={this.state}>
218221
<div class="kol-combobox__group">
219222
<KolInputStateWrapperFc {...this.getInputProps()} />
220-
<CustomSuggestionsToggleFc onClick={this.toggleListbox.bind(this)} disabled={this.state._disabled} />
223+
<CustomSuggestionsToggleFc onClick={this.toggleListbox.bind(this)} disabled={isDisabled} />
221224
</div>
222225

223-
{this._isOpen && !(this.state._disabled === true) && (
226+
{this._isOpen && !isDisabled && (
224227
<CustomSuggestionsOptionsGroupFc blockSuggestionMouseOver={this.blockSuggestionMouseOver} onKeyDown={this.handleKeyDownDropdown.bind(this)}>
225228
{Array.isArray(this._filteredSuggestions) &&
226229
this._filteredSuggestions.length > 0 &&

packages/components/src/components/single-select/shadow.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export class KolSingleSelect implements SingleSelectAPI {
7171

7272
private toggleListbox = (event: Event) => {
7373
event?.preventDefault();
74-
if (this.state._disabled) {
74+
const isDisabled = this.state._disabled === true;
75+
if (isDisabled) {
7576
return;
7677
} else {
7778
if (!this._hasOpened) {
@@ -95,7 +96,8 @@ export class KolSingleSelect implements SingleSelectAPI {
9596
}
9697

9798
private clearSelection() {
98-
if (this.state._disabled) {
99+
const isDisabled = this.state._disabled === true;
100+
if (isDisabled) {
99101
return;
100102
} else {
101103
const emptyValue = null;
@@ -211,6 +213,7 @@ export class KolSingleSelect implements SingleSelectAPI {
211213

212214
private getInputProps(): InputStateWrapperProps {
213215
const { ariaDescribedBy } = getRenderStates(this.state);
216+
const isDisabled = this.state._disabled === true;
214217

215218
return {
216219
'aria-activedescendant': this._isOpen && this._focusedOptionIndex >= 0 ? `option-${this._focusedOptionIndex}` : undefined,
@@ -222,7 +225,7 @@ export class KolSingleSelect implements SingleSelectAPI {
222225
autocapitalize: 'off',
223226
autocorrect: 'off',
224227
class: 'kol-single-select__input',
225-
disabled: this.state._disabled,
228+
disabled: isDisabled,
226229
name: this.state._name,
227230
placeholder: this.state._placeholder,
228231
ref: this.catchRef,
@@ -246,6 +249,7 @@ export class KolSingleSelect implements SingleSelectAPI {
246249
}
247250

248251
public render(): JSX.Element {
252+
const isDisabled = this.state._disabled === true;
249253
return (
250254
<KolFormFieldStateWrapperFc {...this.getFormFieldProps()}>
251255
<KolInputContainerFc state={this.state}>
@@ -262,14 +266,14 @@ export class KolSingleSelect implements SingleSelectAPI {
262266
this.refInput?.focus();
263267
}}
264268
class={clsx('kol-single-select__delete', {
265-
'kol-single-select__delete--disabled': this.state._disabled,
269+
'kol-single-select__delete--disabled': isDisabled,
266270
})}
267271
/>
268272
)}
269273

270-
<CustomSuggestionsToggleFc onClick={this.toggleListbox.bind(this)} disabled={this.state._disabled} />
274+
<CustomSuggestionsToggleFc onClick={this.toggleListbox.bind(this)} disabled={isDisabled} />
271275
</div>
272-
{this._isOpen && !(this.state._disabled === true) && (
276+
{this._isOpen && !isDisabled && (
273277
<CustomSuggestionsOptionsGroupFc
274278
blockSuggestionMouseOver={this.blockSuggestionMouseOver}
275279
onKeyDown={this.handleKeyDownDropdown.bind(this)}

0 commit comments

Comments
 (0)