Skip to content

Commit

Permalink
refactor(components): reduce post-migration TypeScript errors (#10356)
Browse files Browse the repository at this point in the history
Minor refactor - some HTML attributes are reflected to properties.
Thus, we can access properties instead of calling
getAttribute/hasAttribute.
Properties are also more type-safe (where as getAttribute string
parameter does not have type-checking)

And other minor changes.
  • Loading branch information
maxpatiiuk authored Sep 24, 2024
1 parent 427ee46 commit 97d8bb8
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class Button
<InteractiveContainer disabled={this.disabled}>
<Tag
aria-disabled={childElType === "a" ? toAriaBoolean(this.disabled || this.loading) : null}
aria-expanded={this.el.getAttribute("aria-expanded")}
aria-expanded={this.el.ariaExpanded}
aria-label={!this.loading ? getLabelText(this) : this.messages.loading}
aria-live="polite"
class={{
Expand Down
7 changes: 0 additions & 7 deletions packages/calcite-components/src/components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ export class Dialog
[CSS.containerOpen]: opened,
[CSS.containerEmbedded]: this.embedded,
}}
ref={this.setContainerEl}
>
{this.modal ? (
<calcite-scrim class={CSS.scrim} onClick={this.handleOutsideClose} />
Expand Down Expand Up @@ -364,8 +363,6 @@ export class Dialog

transitionEl: HTMLDivElement;

containerEl: HTMLDivElement;

focusTrap: FocusTrap;

private resizePosition: DialogResizePosition = { ...initialResizePosition };
Expand Down Expand Up @@ -764,10 +761,6 @@ export class Dialog
}
}

private setContainerEl = (el: HTMLDivElement): void => {
this.containerEl = el;
};

private setTransitionEl = (el: HTMLDivElement): void => {
this.transitionEl = el;
this.setupInteractions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const Heading: FunctionalComponent<HeadingProps> = (props, children): VNo
delete props.level;

return (
<HeadingTag class={props.class} key={props.key} level={props.level}>
<HeadingTag class={props.class} key={props.key}>
{children}
</HeadingTag>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ export class InputDatePicker

@State() private localeData: DateLocaleData;

private startInput: HTMLCalciteInputElement;
private startInput: HTMLCalciteInputTextElement;

private endInput: HTMLCalciteInputElement;
private endInput: HTMLCalciteInputTextElement;

private floatingEl: HTMLDivElement;

Expand Down Expand Up @@ -884,11 +884,11 @@ export class InputDatePicker
syncHiddenFormInput("date", this, input);
}

setStartInput = (el: HTMLCalciteInputElement): void => {
setStartInput = (el: HTMLCalciteInputTextElement): void => {
this.startInput = el;
};

setEndInput = (el: HTMLCalciteInputElement): void => {
setEndInput = (el: HTMLCalciteInputTextElement): void => {
this.endInput = el;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export class InputTimePicker

@Element() el: HTMLCalciteInputTimePickerElement;

@State() calciteInputEl: HTMLCalciteInputElement;
@State() calciteInputEl: HTMLCalciteInputTextElement;

defaultValue: InputTimePicker["value"];

Expand Down Expand Up @@ -853,7 +853,7 @@ export class InputTimePicker
this.openHandler();
};

private setInputEl = (el: HTMLCalciteInputElement): void => {
private setInputEl = (el: HTMLCalciteInputTextElement): void => {
this.calciteInputEl = el;
};

Expand Down
12 changes: 8 additions & 4 deletions packages/calcite-components/src/components/link/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,19 @@ export class Link implements InteractiveComponent, LoadableComponent {
This works around that issue for now.
*/
download={
Tag === "a" ? (download === true || download === "" ? "" : download || null) : null
childElType === "a"
? download === true || download === ""
? ""
: download || null
: null
}
href={Tag === "a" && this.href}
href={childElType === "a" && this.href}
onClick={this.childElClickHandler}
ref={this.storeTagRef}
rel={Tag === "a" && this.rel}
rel={childElType === "a" && this.rel}
role={role}
tabIndex={tabIndex}
target={Tag === "a" && this.target}
target={childElType === "a" && this.target}
>
{this.iconStart ? iconStartEl : null}
<slot />
Expand Down
2 changes: 1 addition & 1 deletion packages/calcite-components/src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class CalciteMenu implements LocalizedComponent, T9nComponent, LoadableCo
}

private getEffectiveRole(): string {
return this.el.getAttribute("role") || "menubar";
return this.el.role || "menubar";
}

// --------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ export class Tooltip implements FloatingUIComponent, OpenCloseComponent {

guid = `calcite-tooltip-${guid()}`;

hasLoaded = false;

openTransitionProp = "opacity";

transitionEl: HTMLDivElement;
Expand Down Expand Up @@ -175,7 +173,6 @@ export class Tooltip implements FloatingUIComponent, OpenCloseComponent {
if (this.referenceElement && !this.effectiveReferenceElement) {
this.setUpReferenceElement();
}
this.hasLoaded = true;
}

disconnectedCallback(): void {
Expand Down

0 comments on commit 97d8bb8

Please sign in to comment.