Skip to content

Commit

Permalink
chore(ui5-select): migrate to tsx template (#10469)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgogov authored Jan 16, 2025
1 parent 4db8e02 commit e8d4647
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 135 deletions.
51 changes: 0 additions & 51 deletions packages/main/src/Select.hbs

This file was deleted.

10 changes: 4 additions & 6 deletions packages/main/src/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import customElement from "@ui5/webcomponents-base/dist/decorators/customElement
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
import event from "@ui5/webcomponents-base/dist/decorators/event-strict.js";
import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
import {
isSpace,
isUp,
Expand All @@ -19,15 +19,13 @@ import {
import announce from "@ui5/webcomponents-base/dist/util/InvisibleMessage.js";
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js";
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
import "@ui5/webcomponents-icons/dist/slim-arrow-down.js";
import "@ui5/webcomponents-icons/dist/error.js";
import "@ui5/webcomponents-icons/dist/alert.js";
import "@ui5/webcomponents-icons/dist/sys-enter-2.js";
import "@ui5/webcomponents-icons/dist/information.js";
import { isPhone } from "@ui5/webcomponents-base/dist/Device.js";
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
import i18n from "@ui5/webcomponents-base/dist/decorators/i18n.js";
import "@ui5/webcomponents-icons/dist/decline.js";
import type { Timeout } from "@ui5/webcomponents-base/dist/types.js";
import InvisibleMessageMode from "@ui5/webcomponents-base/dist/types/InvisibleMessageMode.js";
import { getScopedVarName } from "@ui5/webcomponents-base/dist/CustomElementsScope.js";
Expand Down Expand Up @@ -56,7 +54,7 @@ import Button from "./Button.js";
import type ListItemBase from "./ListItemBase.js";

// Templates
import SelectTemplate from "./generated/templates/SelectTemplate.lit.js";
import SelectTemplate from "./SelectTemplate.js";

// Styles
import selectCss from "./generated/themes/Select.css.js";
Expand Down Expand Up @@ -130,7 +128,7 @@ type SelectLiveChangeEventDetail = {
tag: "ui5-select",
languageAware: true,
formAssociated: true,
renderer: litRender,
renderer: jsxRenderer,
template: SelectTemplate,
styles: [
selectCss,
Expand Down Expand Up @@ -823,7 +821,7 @@ class Select extends UI5Element implements IFormInputElement {
get _effectiveTabIndex() {
return this.disabled
|| (this.responsivePopover // Handles focus on Tab/Shift + Tab when the popover is opened
&& this.responsivePopover.open) ? "-1" : "0";
&& this.responsivePopover.open) ? -1 : 0;
}

/**
Expand Down
78 changes: 0 additions & 78 deletions packages/main/src/SelectPopover.hbs

This file was deleted.

106 changes: 106 additions & 0 deletions packages/main/src/SelectPopoverTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import type Select from "./Select.js";
import List from "./List.js";
import Button from "./Button.js";
import ResponsivePopover from "./ResponsivePopover.js";
import Popover from "./Popover.js";
import Icon from "./Icon.js";
import decline from "@ui5/webcomponents-icons/dist/decline.js";

export default function SelectPopoverTemplate(this: Select) {
return (
<>
{this.options.length > 0 &&
<ResponsivePopover
class={{
"ui5-select-popover": true,
...this.classes.popover
}}
part="popover"
style={this.styles.responsivePopover}
placement="Bottom"
horizontalAlign="Start"
hideArrow={true}
preventInitialFocus={true}
onOpen={this._afterOpen}
onBeforeOpen={this._beforeOpen}
onClose={this._afterClose}
onKeyDown={this._onkeydown}
>
{this._isPhone &&
<div slot="header" class="ui5-responsive-popover-header">
<div class="row">
<span>{this._headerTitleText}</span>
<Button
class="ui5-responsive-popover-close-btn"
icon={decline}
design="Transparent"
onClick={this._toggleRespPopover} />
</div>

{this.hasValueStateText &&
<div class={{
"row": true,
"ui5-select-value-state-dialog-header": true,
...this.classes.popoverValueState
}}>
{valueStateMessage.call(this)}
</div>
}
</div>
}

{!this._isPhone && this.hasValueStateText &&
<div
class={this.classes.popoverValueState}
style={this.styles.responsivePopoverHeader}>
<Icon
class="ui5-input-value-state-message-icon"
name={this._valueStateMessageInputIcon} />
{valueStateMessage.call(this)}
</div>
}

<List
separators="None"
onMouseDown={this._itemMousedown}
onItemClick={this._handleItemPress}
>
<slot></slot>
</List>
</ResponsivePopover>
}

{this.shouldOpenValueStateMessagePopover &&
<Popover
part="popover"
class="ui5-valuestatemessage-popover"
preventInitialFocus={true}
preventFocusRestore={true}
hideArrow={true}
placement="Bottom"
horizontalAlign="Start"
>
<div
class={this.classes.popoverValueState}
style={this.styles.popoverHeader}>
<Icon
class="ui5-input-value-state-message-icon"
name={this._valueStateMessageInputIcon} />
{valueStateMessage.call(this)}
</div>
</Popover>
}
</>
);
}

function valueStateMessage(this: Select) {
return (
<>
{this.shouldDisplayDefaultValueStateMessage
? this.valueStateText
: <slot name="valueStateMessage"></slot>
}
</>
);
}
68 changes: 68 additions & 0 deletions packages/main/src/SelectTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type Select from "./Select.js";
import Icon from "./Icon.js";
import slimArrowDown from "@ui5/webcomponents-icons/dist/slim-arrow-down.js";
import SelectPopoverTemplate from "./SelectPopoverTemplate.js";

export default function SelectTemplate(this: Select) {
return (
<>
<div
class={{
"ui5-select-root": true,
"ui5-input-focusable-element": true,
}}
id={`${this._id}-select`}
onClick={this._onclick}
>
{this.selectedOptionIcon &&
<Icon
mode="Decorative"
class="ui5-select-option-icon"
name={this.selectedOptionIcon} />
}

<div
class="ui5-select-label-root"
data-sap-focus-ref
tabindex={this._effectiveTabIndex}
role="combobox"
aria-haspopup="listbox"
aria-label={this.ariaLabelText}
aria-describedby={this.valueStateTextId}
aria-disabled={this.isDisabled}
aria-required={this.required}
aria-readonly={this.readonly}
aria-expanded={this._isPickerOpen}
aria-roledescription={this._ariaRoleDescription}
onKeyDown={this._onkeydown}
onKeyPress={this._handleKeyboardNavigation}
onKeyUp={this._onkeyup}
onFocusIn={this._onfocusin}
onFocusOut={this._onfocusout}
>
{this.hasCustomLabel
? <slot name="label"></slot>
: this.text
}
</div>

{!this.readonly &&
<Icon
name={slimArrowDown}
class={{
"inputIcon": true,
"inputIcon--pressed": this._iconPressed,
}} />
}

{this.hasValueState &&
<span id={`${this._id}-valueStateDesc`} class="ui5-hidden-text">
{this.valueStateText}
</span>
}
</div>

{SelectPopoverTemplate.call(this)}
</>
);
}

0 comments on commit e8d4647

Please sign in to comment.