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(ui5-segmented-button-item): implement segmented button item independently from button #8669

Merged
merged 75 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
4390a18
Merge remote-tracking branch 'origin/main' into release-2.0
Mar 21, 2024
7656a93
refactor(framework): remove internet explorer related checks (#8494)
nnaydenow Mar 21, 2024
aa463d9
refactor(framework): remove the CSP module (#8496)
nnaydenow Mar 21, 2024
601247e
refactor(ui5-card): remove ICardHeader interface (#8497)
dimovpetar Mar 21, 2024
492e338
refactor(ui5-upload-collection): remove IUploadCollectionItem interfa…
dimovpetar Mar 22, 2024
e44547c
refactor(ui5-busy-indicator): rename BusyIndicatorSize values to S, M…
dimovpetar Mar 22, 2024
e5c7faf
refactor(ui5-card-header): rename status to additionalText (#8507)
dimovpetar Mar 22, 2024
a3aa04e
refactor(ui5-carousel): rename pageIndicatorStyle to pageIndicatorTyp…
dimovpetar Mar 22, 2024
62d235d
refactor(framework): remove render method (#8501)
nnaydenow Mar 22, 2024
17ae152
refactor(tools): remove js option from generation templates (#8503)
nnaydenow Mar 22, 2024
96dca3c
Merge branch 'main' into rel-2.0
ilhan007 Mar 22, 2024
0789c34
chore: remove unused command (#8506)
nnaydenow Mar 22, 2024
d6f2836
refactor(ui5-popover): rename PopoverHorizontalAlign and PopoverPlace…
dimovpetar Mar 25, 2024
1d726ea
Merge branch 'main' into release-2.0
ilhan007 Mar 25, 2024
a59844f
docs: deploy v2 preview
ilhan007 Mar 25, 2024
fc963c7
Merge branch 'main' into release-2.0
ilhan007 Mar 25, 2024
0b8c7d3
refactor(icons): remove soccor icon (#8524)
nnaydenow Mar 25, 2024
7f20176
refactor(icons-business-suite): remove add-polygone icon (#8525)
nnaydenow Mar 25, 2024
194b6b3
refactor(tools): remove jsdoc plugin (#8518)
nnaydenow Mar 25, 2024
d7bb8ac
refactor: remove all Assets-static.js modules (#8526)
ilhan007 Mar 25, 2024
111e585
refactor(ui5-calendar): rename `selected-dates-change` to `selectio…
tsanislavgatev Mar 25, 2024
6b7237e
docs: update keyboard keys abbreviations (#8528)
ilhan007 Mar 25, 2024
76946c8
Merge branch 'main' into release-2.0
ilhan007 Mar 25, 2024
7f61f6d
Update docusaurus.config.ts
ilhan007 Mar 25, 2024
5bfa36d
docs: add reset button in playground (#8531)
pskelin Mar 25, 2024
48703b0
Update index.js
pskelin Mar 25, 2024
34a753c
chore: update chromedriver (#8532)
pskelin Mar 25, 2024
c40ff8c
chore: update LocaleData.ts
petyabegovska Mar 26, 2024
e7ae45a
feat(framework): support sr, mk, cnr locales (#8534)
ilhan007 Mar 26, 2024
d7a1e9d
docs(ui5-segmented-button-item): add notes to inherited properties (#…
tsanislavgatev Mar 26, 2024
d417aec
chore: update yarn.lock
ilhan007 Mar 26, 2024
5f12fd9
Merge branch 'main' into release-2.0
ilhan007 Mar 27, 2024
e9cb499
refactor(ui5-color-picker): rename `color` to `value` (#8538)
tsanislavgatev Mar 27, 2024
83ee0cc
refactor(tools): enable TypeScript as default (#8521)
nnaydenow Mar 27, 2024
8f6a40f
refactor(ui5-color-palette): remove deprecated APIs (#8542)
unazko Mar 27, 2024
2435f56
refactor(ui5-bar): move to `main` (#8548)
tsanislavgatev Mar 27, 2024
33b2e0b
Merge branch 'main' into release-2.0
ilhan007 Mar 27, 2024
94bc1ff
chore(ui5-bar): fix import in samples (#8555)
tsanislavgatev Mar 27, 2024
6c42f86
Merge branch 'main' into release-2.0
ilhan007 Mar 28, 2024
37cb9d3
refactor(ui5-tab): rename `subTabs` slot to `items` (#8559)
kskondov Mar 28, 2024
3da1e47
refactor(ui5-tabcontainer): rename `tabs-overflow-mode` to `overflow-…
kskondov Mar 28, 2024
d3e2ed1
refactor(ui5-tabcontainer): remove TabContainerBackgroundDesign enume…
kskondov Mar 28, 2024
c742654
chore: enable tree tests (#8558)
nnaydenow Mar 28, 2024
9db92d9
chore(release): publish v1.24.0-rc.3 [ci skip]
ui5-webcomponents-bot Mar 28, 2024
1690702
Merge branch 'main' into release-2.0
ilhan007 Mar 29, 2024
13c9c58
refactor(ui5-tabcontainer): remove deprecated showOverflow property (…
kskondov Mar 29, 2024
18e2759
refactor(ui5-popover): rename property placementType to placement (#8…
dimovpetar Apr 1, 2024
4557fa7
Merge branch 'main' into release-2.0
ilhan007 Apr 1, 2024
016f237
Merge branch 'main' into release-2.0
ilhan007 Apr 2, 2024
b06c349
framework: enable popover API (#8192)
nnaydenow Apr 2, 2024
071de87
chore: integrate the popover API with OpenUI5 (#8606)
vladitasev Apr 2, 2024
08f7a54
refactor(ui5-illustrated-message): rename `size` property to `design`…
yanaminkova Apr 3, 2024
b7747fa
refactor(ui5-segmented-button-item): separate from button
tsanislavgatev Apr 5, 2024
50244c3
refactor(ui5-segmented-button-item): separate from button
tsanislavgatev Apr 5, 2024
231341d
fix(ui5-segmented-button-item): merge main
tsanislavgatev Apr 5, 2024
62e9815
fix(ui5-segmented-button-item): merge main
tsanislavgatev Apr 5, 2024
1acc1f2
fix(ui5-segmented-button-item): fix test
tsanislavgatev Apr 8, 2024
832b5b7
fix(ui5-segmented-button-item): align controls and samples
tsanislavgatev Apr 8, 2024
a4447d2
fix(ui5-segmentedbutton-item): fix timepicker tests
tsanislavgatev Apr 8, 2024
b463bf3
fix(ui5-segmentedbutton-item): fix timepicker tests
tsanislavgatev Apr 8, 2024
28af510
fix(ui5-segmentedbutton-item): fix storybook
tsanislavgatev Apr 8, 2024
2b84a8e
Merge branch 'main' into segmented-button-item
tsanislavgatev Apr 12, 2024
49f630a
refactor(ui5-segmentedbutton-item): refactor focus handling
tsanislavgatev Apr 15, 2024
d4156c6
refactor(ui5-segmentedbutton-item): refactor focus handling
tsanislavgatev Apr 15, 2024
969d7df
refactor(ui5-segmentedbutton-item): refactor focus handling
tsanislavgatev Apr 15, 2024
2738ac6
fix(ui5-segmented-button-item): samples fix
tsanislavgatev Apr 15, 2024
0ed79df
fix(ui5-segmented-button-item): fix comments
tsanislavgatev Apr 15, 2024
62f110b
fix(ui5-segmented-button-item): fix styling
tsanislavgatev Apr 17, 2024
64f677a
docs(ui5-segmented-button-item): fix typos
tsanislavgatev Apr 22, 2024
a19de77
fix(ui5-segmented-button-item): address comments
tsanislavgatev Apr 25, 2024
d472d3e
fix(ui5-segmented-button-item): address comments
tsanislavgatev Apr 25, 2024
660a374
Merge branch 'main' into segmented-button-item
tsanislavgatev Apr 25, 2024
b81051a
fix(ui5-segmented-button-item): remove redundant dot
tsanislavgatev Apr 25, 2024
754ac22
refactor(ui5-segmented-button-item): reuse css parameters
tsanislavgatev Apr 26, 2024
50c21a6
fix(ui5-segmented-button): merge main
tsanislavgatev Apr 26, 2024
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
4 changes: 2 additions & 2 deletions packages/fiori/src/ViewSettingsDialog.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
<div class="ui5-vsd-sub-header">
<ui5-segmented-button @ui5-selection-change="{{_handleModeChange}}">
<ui5-segmented-button-item
?pressed="{{isModeSort}}"
?selected="{{isModeSort}}"
icon="sort"
mode="Sort"
></ui5-segmented-button-item>
<ui5-segmented-button-item
?pressed="{{isModeFilter}}"
?selected="{{isModeFilter}}"
icon="filter"
mode="Filter"
></ui5-segmented-button-item>
Expand Down
14 changes: 6 additions & 8 deletions packages/main/src/SegmentedButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import SegmentedButtonCss from "./generated/themes/SegmentedButton.css.js";
*/
interface ISegmentedButtonItem extends UI5Element, ITabbable {
disabled: boolean,
pressed: boolean,
selected: boolean,
}

type SegmentedButtonSelectionChangeEventDetail = {
Expand All @@ -44,7 +44,6 @@ type SegmentedButtonSelectionChangeEventDetail = {
* one of the items, it stays in a pressed state. It automatically resizes the items
* to fit proportionally within the component. When no width is set, the component uses the available width.
*
* **Note:** There can be just one selected `item` at a time.
*
* ### ES6 Module Import
*
Expand Down Expand Up @@ -172,7 +171,7 @@ class SegmentedButton extends UI5Element {
switch (this.selectionMode) {
case SegmentedButtonSelectionMode.Multiple:
if (e instanceof KeyboardEvent) {
target.pressed = !target.pressed;
target.selected = !target.selected;
}
break;
default:
Expand All @@ -184,16 +183,15 @@ class SegmentedButton extends UI5Element {
});

this._itemNavigation.setCurrentItem(target);
target.focus();

return this;
}

_applySingleSelection(item: ISegmentedButtonItem) {
this.items.forEach(currentItem => {
currentItem.pressed = false;
currentItem.selected = false;
});
item.pressed = true;
item.selected = true;
this._selectedItem = item;
}

Expand Down Expand Up @@ -236,8 +234,8 @@ class SegmentedButton extends UI5Element {
// If the component is focused for the first time
// focus the selected item if such is present
if (this.selectedItems.length) {
this.selectedItems[0].focus();
this._itemNavigation.setCurrentItem(this.selectedItems[0]);
this.selectedItems[0].focus();
this.hasPreviouslyFocusedItem = true;
}
}
Expand All @@ -249,7 +247,7 @@ class SegmentedButton extends UI5Element {
* @default []
*/
get selectedItems(): Array<ISegmentedButtonItem> {
return this.items.filter(item => item.pressed);
return this.items.filter(item => item.selected);
}

get ariaDescribedBy() {
Expand Down
20 changes: 5 additions & 15 deletions packages/main/src/SegmentedButtonItem.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,29 @@
aria-roledescription="{{ariaDescription}}"
aria-posinset="{{posInSet}}"
aria-setsize="{{sizeOfSet}}"
aria-selected="{{pressed}}"
class="ui5-button-root"
aria-selected="{{selected}}"
class="ui5-segmented-button-item-root"
aria-disabled="{{disabled}}"
data-sap-focus-ref
{{> ariaPressed}}
@focusout={{_onfocusout}}
@focusin={{_onfocusin}}
@click={{_onclick}}
@mousedown={{_onmousedown}}
@mouseup={{_onmouseup}}
@keydown={{_onkeydown}}
@keyup={{_onkeyup}}
@touchstart="{{_ontouchstart}}"
@touchend="{{_ontouchend}}"
tabindex={{tabIndexValue}}
aria-label="{{ariaLabelText}}"
title="{{tooltip}}"
>
{{#if icon}}
<ui5-icon
class="ui5-button-icon"
class="ui5-segmented-button-item-icon"
name="{{icon}}"
part="icon"
?show-tooltip={{showIconTooltip}}
?show-tooltip={{isIconOnly}}
></ui5-icon>
{{/if}}

<span id="{{_id}}-content" class="ui5-button-text">
<span id="{{_id}}-content" class="ui5-segmented-button-item-text">
<bdi>
<slot></slot>
</bdi>
</span>

</li>

{{#*inline "ariaPressed"}}{{/inline}}
142 changes: 106 additions & 36 deletions packages/main/src/SegmentedButtonItem.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
import property from "@ui5/webcomponents-base/dist/decorators/property.js";

import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import I18nBundle, { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import { isDesktop } from "@ui5/webcomponents-base/dist/Device.js";
import { isSpaceShift } from "@ui5/webcomponents-base/dist/Keys.js";
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
import willShowContent from "@ui5/webcomponents-base/dist/util/willShowContent.js";
import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";

import { SEGMENTEDBUTTONITEM_ARIA_DESCRIPTION } from "./generated/i18n/i18n-defaults.js";
import type { ISegmentedButtonItem } from "./SegmentedButton.js";
import SegmentedButtonItemTemplate from "./generated/templates/SegmentedButtonItemTemplate.lit.js";

import ToggleButton from "./ToggleButton.js";
import ButtonDesign from "./types/ButtonDesign.js";
import ButtonType from "./types/ButtonType.js";
import ButtonAccessibleRole from "./types/ButtonAccessibleRole.js";
import { AccessibilityAttributes } from "./Button.js";
import { IButton } from "./Button.js";
import Icon from "./Icon.js";

import { SEGMENTEDBUTTONITEM_ARIA_DESCRIPTION } from "./generated/i18n/i18n-defaults.js";

import segmentedButtonItemCss from "./generated/themes/SegmentedButtonItem.css.js";
/**
* @class
*
* ### Overview
*
* Users can use the `ui5-segmented-button-item` as part of a `ui5-segmented-button`.
*
* Clicking or tapping on a `ui5-segmented-button-item` changes its state to `pressed`.
* Clicking or tapping on a `ui5-segmented-button-item` changes its state to `selected`.
* The item returns to its initial state when the user clicks or taps on it again.
* By applying additional custom CSS-styling classes, apps can give a different style to any
* `ui5-segmented-button-item`.
Expand All @@ -30,63 +34,72 @@ import { SEGMENTEDBUTTONITEM_ARIA_DESCRIPTION } from "./generated/i18n/i18n-defa
*
* `import "@ui5/webcomponents/dist/SegmentedButtonItem.js";`
* @constructor
* @extends ToggleButton
* @implements { ISegmentedButtonItem }
* @extends UI5Element
* @implements { ISegmentedButtonItem, IButton }
* @public
*/
@customElement({
tag: "ui5-segmented-button-item",
renderer: litRender,
template: SegmentedButtonItemTemplate,
styles: segmentedButtonItemCss,
dependencies: [Icon],
})
class SegmentedButtonItem extends ToggleButton implements ISegmentedButtonItem {
class SegmentedButtonItem extends UI5Element implements IButton, ISegmentedButtonItem {
/**
* **Note:** The property is inherited and not supported. If set, it won't take any effect.
* @default "Default"
* Defines whether the component is disabled.
* A disabled component can't be selected or
* focused, and it is not in the tab chain.
* @default false
* @public
*/
@property({ type: ButtonDesign, defaultValue: ButtonDesign.Default })
declare design: `${ButtonDesign}`;
@property({ type: Boolean })
disabled!: boolean;

/**
* **Note:** The property is inherited and not supported. If set, it won't take any effect.
* Determines whether the component is displayed as selected.
* @default false
* @public
*/
@property({ type: Boolean })
declare iconEnd: boolean;
selected!: boolean;

/**
* **Note:** The property is inherited and not supported. If set, it won't take any effect.
* @default false
* Defines the tooltip of the component.
*
* **Note:** A tooltip attribute should be provided for icon-only buttons, in order to represent their exact meaning/function.
* @default ""
* @public
* @since 1.2.0
*/
@property({ type: Boolean })
declare submits: boolean;
@property()
tooltip!: string;

/**
* **Note:** The property is inherited and not supported. If set, it won't take any effect.
* @default {}
* Defines the icon, displayed as graphical element within the component.
* The SAP-icons font provides numerous options.
*
* Example:
* See all the available icons within the [Icon Explorer](https://sdk.openui5.org/test-resources/sap/m/demokit/iconExplorer/webapp/index.html).
* @default ""
* @public
*/
@property({ type: Object })
declare accessibilityAttributes: AccessibilityAttributes;
@property()
icon!: string;

/**
* **Note:** The property is inherited and not supported. If set, it won't take any effect.
* @default "Button"
* @public
* Indicates if the element is focusable
* @private
*/
@property({ type: ButtonType, defaultValue: ButtonType.Button })
declare type: `${ButtonType}`;
@property({ type: Boolean })
nonInteractive!: boolean;

/**
* **Note:** The property is inherited and not supported. If set, it won't take any effect.
* @default "Button"
* @public
* Defines the tabIndex of the component.
* @private
*/
@property({ type: ButtonAccessibleRole, defaultValue: ButtonAccessibleRole.Button })
declare accessibleRole: `${ButtonAccessibleRole}`;
@property({ type: String, defaultValue: "0", noAttribute: true })
forcedTabIndex!: string;

/**
* Defines the index of the item inside of the SegmentedButton.
Expand All @@ -104,9 +117,66 @@ class SegmentedButtonItem extends ToggleButton implements ISegmentedButtonItem {
@property({ validator: Integer, defaultValue: 0 })
sizeOfSet!: number;

/**
* Defines the text of the component.
*
* **Note:** Although this slot accepts HTML Elements, it is strongly recommended that you only use text in order to preserve the intended design.
* @public
*/
@slot({ type: Node, "default": true })
text!: Array<Node>;

static i18nBundle: I18nBundle;

get ariaDescription() {
return SegmentedButtonItem.i18nBundle.getText(SEGMENTEDBUTTONITEM_ARIA_DESCRIPTION);
}

constructor() {
super();
}

_onclick() {
this.selected = !this.selected;
}

onEnterDOM() {
if (isDesktop()) {
this.setAttribute("desktop", "");
}
}

_onkeyup(e: KeyboardEvent) {
if (isSpaceShift(e)) {
e.preventDefault();
}
}

get isIconOnly() {
return !willShowContent(this.text);
}

get tabIndexValue() {
const tabindex = this.getAttribute("tabindex");

if (tabindex) {
return tabindex;
}

return this.forcedTabIndex;
}

get ariaLabelText() {
return getEffectiveAriaLabelText(this);
}

get showIconTooltip() {
return this.isIconOnly && !this.tooltip;
}

static async onDefine() {
SegmentedButtonItem.i18nBundle = await getI18nBundle("@ui5/webcomponents");
}
}

SegmentedButtonItem.define();
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/TimePickerInternals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type TimePickerComponentIndexMap = {

type TimeSelectionPeriodProperties = {
label: string,
pressed: boolean,
selected: boolean,
}

type TimeSelectionChangeEventDetail = {
Expand Down Expand Up @@ -421,7 +421,7 @@ class TimePickerInternals extends UI5Element {
this.periodsArray.forEach(item => {
this._periods.push({
"label": item,
"pressed": this._period === item,
"selected": this._period === item,
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/TimeSelectionClocks.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
>
{{#each _periods}}
<ui5-segmented-button-item
?pressed={{this.pressed}}
?selected={{this.selected}}
>
{{this.label}}
</ui5-segmented-button-item>
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/TimeSelectionClocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ class TimeSelectionClocks extends TimePickerInternals {
// A/P selects AM/PM segmented button item
const buttonAmPm = this._buttonAmPm();
if (buttonAmPm) {
buttonAmPm.items[0].pressed = isKeyA(evt);
buttonAmPm.items[1].pressed = isKeyP(evt);
buttonAmPm.items[0].selected = isKeyA(evt);
buttonAmPm.items[1].selected = isKeyP(evt);
const period = isKeyA(evt) ? buttonAmPm.items[0].textContent : buttonAmPm.items[1].textContent;
period && this._calculatePeriodChange(period);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/TimeSelectionInputs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
>
{{#each _periods}}
<ui5-segmented-button-item
?pressed={{this.pressed}}
?selected={{this.selected}}
>
{{this.label}}
</ui5-segmented-button-item>
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/themes/SegmentedButton.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
background-color: var(--sapButton_Hover_Background);
}

::slotted([ui5-segmented-button-item][pressed]),
::slotted([ui5-segmented-button-item][selected]),
::slotted([ui5-segmented-button-item][active]) {
border-color: var(--sapButton_Selected_BorderColor);
background-color: var(--sapButton_Selected_Background);
color: var(--sapButton_Selected_TextColor);
}

::slotted([ui5-segmented-button-item][pressed]:hover) {
::slotted([ui5-segmented-button-item][selected]:hover) {
border-color: var(--sapButton_Selected_Hover_BorderColor);
background-color: var(--sapButton_Selected_Hover_Background);
color: var(--sapButton_Selected_TextColor);
Expand Down
Loading