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: do not use Host in functional components #10352

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Event,
EventEmitter,
h,
Host,
Listen,
Method,
Prop,
Expand All @@ -21,6 +22,7 @@ import { createObserver } from "../../utils/observers";
import { HeadingLevel } from "../functional/Heading";
import type { ValueUnion } from "../types";
import { logger } from "../../utils/logger";
import { toAriaBoolean } from "../../utils/dom";
import { ICON_TYPES } from "./resources";
import {
calciteInternalListItemValueChangeHandler,
Expand Down Expand Up @@ -302,6 +304,10 @@ export class PickList<
}

render(): VNode {
return <List onKeyDown={this.keyDownHandler} props={this} />;
return (
<Host aria-busy={toAriaBoolean(this.loading)} onKeyDown={this.keyDownHandler} role="menu">
<List props={this} />
</Host>
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { FunctionalComponent, h, Host, VNode } from "@stencil/core";
import { FunctionalComponent, h, VNode } from "@stencil/core";
import { JSXBase } from "@stencil/core/internal";
import { toAriaBoolean } from "../../utils/dom";
import { InteractiveContainer } from "../../utils/interactive";
import { CSS, SLOTS } from "./resources";
import { handleFilter, handleFilterEvent } from "./shared-list-logic";
Expand All @@ -25,9 +24,7 @@ interface ListProps extends DOMAttributes {
storeAssistiveEl?: (el: HTMLSpanElement) => void;
}

export const List: FunctionalComponent<
{ props: ListProps } & Pick<DOMAttributes, "onBlur" | "onFocusin" | "onKeyDown">
> = ({
export const List: FunctionalComponent<{ props: ListProps }> = ({
props: {
disabled,
loading,
Expand All @@ -40,43 +37,32 @@ export const List: FunctionalComponent<
dragEnabled,
storeAssistiveEl,
},
onBlur,
onFocusin,
onKeyDown,
}): VNode => {
const defaultSlot = <slot />;
return (
<Host
aria-busy={toAriaBoolean(loading)}
onBlur={onBlur}
onFocusin={onFocusin}
onKeyDown={onKeyDown}
role="menu"
>
<InteractiveContainer disabled={disabled}>
<section>
{dragEnabled ? (
<span aria-live="assertive" class="assistive-text" ref={storeAssistiveEl} />
<InteractiveContainer disabled={disabled}>
<section>
{dragEnabled ? (
<span aria-live="assertive" class="assistive-text" ref={storeAssistiveEl} />
) : null}
<header class={{ [CSS.sticky]: true }}>
{filterEnabled ? (
<calcite-filter
aria-label={filterPlaceholder}
disabled={disabled}
items={dataForFilter}
onCalciteFilterChange={handleFilterEvent}
placeholder={filterPlaceholder}
ref={setFilterEl}
value={filterText}
/>
) : null}
<header class={{ [CSS.sticky]: true }}>
{filterEnabled ? (
<calcite-filter
aria-label={filterPlaceholder}
disabled={disabled}
items={dataForFilter}
onCalciteFilterChange={handleFilterEvent}
placeholder={filterPlaceholder}
ref={setFilterEl}
value={filterText}
/>
) : null}
<slot name={SLOTS.menuActions} />
</header>
{loading ? <calcite-scrim loading={loading} /> : null}
{defaultSlot}
</section>
</InteractiveContainer>
</Host>
<slot name={SLOTS.menuActions} />
</header>
{loading ? <calcite-scrim loading={loading} /> : null}
{defaultSlot}
</section>
</InteractiveContainer>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Event,
EventEmitter,
h,
Host,
Listen,
Method,
Prop,
Expand Down Expand Up @@ -59,7 +60,7 @@ import {
disconnectSortableComponent,
SortableComponent,
} from "../../utils/sortableComponent";
import { focusElement } from "../../utils/dom";
import { focusElement, toAriaBoolean } from "../../utils/dom";
import { logger } from "../../utils/logger";
import { ValueListMessages } from "./assets/value-list/t9n";
import { CSS, ICON_TYPES } from "./resources";
Expand Down Expand Up @@ -511,12 +512,15 @@ export class ValueList<

render(): VNode {
return (
<List
<Host
aria-busy={toAriaBoolean(this.loading)}
onBlur={this.handleBlur}
onFocusin={this.handleFocusIn}
onKeyDown={this.keyDownHandler}
props={this}
/>
role="menu"
>
<List props={this} />
</Host>
);
}
}
Loading