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

refactor(components): reduce post-migration TypeScript errors #10356

Merged
merged 4 commits into from
Sep 24, 2024

Conversation

maxpatiiuk
Copy link
Member

@maxpatiiuk maxpatiiuk commented Sep 19, 2024

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.

@github-actions github-actions bot added the refactor Issues tied to code that needs to be significantly reworked. label Sep 19, 2024
@@ -764,10 +761,6 @@ export class Dialog
}
}

private setContainerEl = (el: HTMLDivElement): void => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never read, thus removed

@@ -774,9 +774,9 @@ export class InputDatePicker

@State() private localeData: DateLocaleData;

private startInput: HTMLCalciteInputElement;
private startInput: HTMLCalciteInputTextElement;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing a type error in Lumina - the ref is assigned to calcite-input-text, but the type here was calcite-input.

packages/calcite-components/src/components/input/input.tsx Outdated Show resolved Hide resolved
@@ -146,8 +146,6 @@ export class Tooltip implements FloatingUIComponent, OpenCloseComponent {

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

hasLoaded = false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never read

@@ -228,7 +228,7 @@ export class CalciteMenu implements LocalizedComponent, T9nComponent, LoadableCo
}

private getEffectiveRole(): string {
return this.el.getAttribute("role") || "menubar";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

equivalent

@jcfranco
Copy link
Member

I think Firefox ESR prevents us from using ARIA-related properties (e.g., ariaExpanded was added in FF 119).

@dasa does this seem accurate to you?

Sidebar: noticed value-list (deprecated) currently uses ariaLabel.

@dasa
Copy link
Member

dasa commented Sep 23, 2024

We're planning to only support ESR 128 in our next release: https://whattrainisitnow.com/release/?version=esr

Copy link
Member

@jcfranco jcfranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @maxpatiiuk!

Along the same lines of #10352, since some additional refactors were made to files unrelated to simplifying reflected attribute accesses, can you either:

  1. separate non-Host-related refactors to a separate PR?
  2. update the PR title to convey all PR changes?

Thanks!

@jcfranco
Copy link
Member

Thanks for chiming in, @dasa!

@maxpatiiuk maxpatiiuk changed the title refactor: simplify reflected attribute accesses refactor(components): reduce post-migration TypeScript errors Sep 24, 2024
@maxpatiiuk
Copy link
Member Author

I think Firefox ESR prevents us from using ARIA-related properties (e.g., ariaExpanded was added in FF 119).

We're planning to only support ESR 128 in our next release: https://whattrainisitnow.com/release/?version=esr

@jcfranco so if the next release of JS API will drop Firefox 115 ESR support, is Calcite going to do the same for Calcite 3.0 release?
If so, are we ok to use aria properties in this PR or should I revert the change?

`Tag` and `childElType` are the same in Stencil, but will be different
in Lit - so we should use `childElType` in places where the string check
is needed.
@maxpatiiuk maxpatiiuk force-pushed the max/simplify-reflected-attributes branch from 2305e01 to a73a79d Compare September 24, 2024 19:21
@@ -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}>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

level prop doesn't seem to exist in the DOM?
was it used for styling or testing? if not, we should remove it


original discussion in #10352 (comment)

@@ -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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per line 103 in this file (const Tag = childElType;), Tag and childElType variables have the same value in Stencil - thus this change should have no runtime impact.
However, in Lit, Tag function has a bit different type to comply with Lit's dynamic tag name syntax.

See Lumina's docs on JSX -> Dynamic tag names for more details

@jcfranco
Copy link
Member

jcfranco commented Sep 24, 2024

If so, are we ok to use aria properties in this PR or should I revert the change?

Sorry for not clarifying earlier. We should be good to use ARIA properties.

Copy link
Member

@jcfranco jcfranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome stuff, @maxpatiiuk! Thanks! 🚀

@jcfranco jcfranco added the skip visual snapshots Pull requests that do not need visual regression testing. label Sep 24, 2024
@jcfranco jcfranco merged commit 97d8bb8 into dev Sep 24, 2024
15 checks passed
@jcfranco jcfranco deleted the max/simplify-reflected-attributes branch September 24, 2024 23:16
benelan added a commit that referenced this pull request Sep 26, 2024
…tracking

* origin/dev: (40 commits)
  feat: add parcel parameter (#10384)
  feat(alert): apply --calcite-alert-corner-radius to internal close button (#10388)
  feat(dialog, panel): Add css properties for background-color (#10387)
  fix: remove aria-disabled from components where necessary (#10374)
  feat(action-group, block, panel): add `menuPlacement` and `menuFlipPlacements` properties (#10249)
  fix(list, filter): fix sync between list items and filtered data (#10342)
  feat(popover): apply component tokens to arrow (#10386)
  feat(list-item): add `unavailable` property (#10377)
  fix(segmented-control): honor appearance, layout and scale when items are added after initialization (#10368)
  fix(action-pad): fix horizontal action group alignment (#10359)
  fix(combobox): selection-mode="single-persist" correctly selects an item when items have same values (#10366)
  fix(input-time-zone): fix region mode labeling and value mapping (#10345)
  fix(dropdown): open dropdown on `ArrowDown` & `ArrowUp` keys (#10264)
  refactor(components): reduce post-migration TypeScript errors (#10356)
  refactor: do not use Host in functional components (#10352)
  refactor(tests): reduce TypeScript errors (#10344)
  feat(alert): add component tokens (#10218)
  fix(card): properly handle slotted elements (#10378)
  refactor(panel): remove duplicate tailwind class (#10379)
  feat(popover, action): add component tokens (#10253)
  ...
benelan added a commit that referenced this pull request Sep 30, 2024
…estone-estimates

* origin/dev: (29 commits)
  fix(input-time-zone): fix region mode labeling and value mapping (#10345)
  fix(dropdown): open dropdown on `ArrowDown` & `ArrowUp` keys (#10264)
  refactor(components): reduce post-migration TypeScript errors (#10356)
  refactor: do not use Host in functional components (#10352)
  refactor(tests): reduce TypeScript errors (#10344)
  feat(alert): add component tokens (#10218)
  fix(card): properly handle slotted elements (#10378)
  refactor(panel): remove duplicate tailwind class (#10379)
  feat(popover, action): add component tokens (#10253)
  chore(t9n): add translations (#10339)
  feat: add 3d building, 3d building parameter, divide, parcel, spaces, spaces parameter, square brackets x, n variable, zoning parameter (#10373)
  build: update browserslist db (#10370)
  ci: resolve husky pre-push and pre-commit errors (#10365)
  docs: update component READMEs (#10371)
  feat(text-area): add component tokens (#10343)
  fix(action): prefer `disabled` in favor of `aria-disabled` (#10367)
  docs(a11y): add reference to a11y guidance to issue template (#10372)
  chore(action): add new string for accessible indicator label (#10360)
  feat(chip): add component tokens (#10179)
  feat(avatar): add component tokens (#10280)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Issues tied to code that needs to be significantly reworked. skip visual snapshots Pull requests that do not need visual regression testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants