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

feat(ui5-segmented-button-item): introduce new component to serve as child of SegmentedButton #3258

Merged
merged 29 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
424149f
initial push
terezamch May 12, 2021
ae3eb86
working version
terezamch May 12, 2021
13770f4
DOM structure corrected
terezamch May 13, 2021
fce59bb
aria description from i18n added
terezamch May 13, 2021
862e9b4
ui5-segmentedbutton-item uses its own styles
terezamch May 13, 2021
e03ff29
minor adjustments:
terezamch May 14, 2021
89f1688
indentation fixes
terezamch May 14, 2021
19759b6
minor ling errors fixed
terezamch May 17, 2021
224bc05
tests adjusted to the new structure of segmented button
terezamch May 17, 2021
5a80558
ACC improvements added
terezamch May 18, 2021
04c46ae
ACC adjustments
terezamch May 18, 2021
81bc53c
using ui5element as point of extension instead of button
terezamch May 18, 2021
0ecb355
The SegmentedButtonItem now extends the ToggleButton
terezamch May 21, 2021
e7dc47f
minor coding style issues fixed
terezamch May 25, 2021
47438f5
dependencies updated
terezamch May 25, 2021
efced6f
renaming ui5-segmentedbutton-item to ui5-segmented-button-item
terezamch May 28, 2021
10ec2c7
fixing a typo
terezamch May 28, 2021
3f5444d
Merge branch 'master' of github.com:terezamch/ui5-webcomponents into …
terezamch May 28, 2021
c22bd08
Merge branch 'master' of github.com:terezamch/ui5-webcomponents into …
terezamch May 31, 2021
b311858
icon fixed - aligned with the new button icon rendering
terezamch May 31, 2021
c5913aa
fixing comments from the internal review
terezamch May 31, 2021
a039260
DOM attributes updated
terezamch Jun 1, 2021
b0ba302
Merge branch 'master' of github.com:terezamch/ui5-webcomponents into …
terezamch Jun 2, 2021
2e329fb
Merge branch 'master' of github.com:terezamch/ui5-webcomponents into …
terezamch Jun 7, 2021
8560c99
fixed selection with space and enter
terezamch Jun 9, 2021
df5e799
fixed indentation
terezamch Jun 9, 2021
868aaea
Making pressed property public again
terezamch Jun 11, 2021
0585734
renaming "button"->"item"
terezamch Jun 14, 2021
8b0eada
Merge branch 'master' of github.com:terezamch/ui5-webcomponents into …
terezamch Jun 14, 2021
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
1 change: 1 addition & 0 deletions docs/Public Module Imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ For API documentation and samples, please check the [UI5 Web Components Playgrou
| Select | `ui5-select` | `import "@ui5/webcomponents/dist/Select.js";` |
| Select Option | `ui5-option` | comes with `ui5-select ` |
| Segmented Button | `ui5-segmented-button` | `import "@ui5/webcomponents/dist/SegmentedButton.js";` |
| Segmented Button Item | `ui5-segmented-button-item`| comes with `ui5-segmented-button ` |
| Suggestion Item | `ui5-suggestion-item` | comes with `InputSuggestions.js` feature - see below |
| Slider | `ui5-slider` | `import "@ui5/webcomponents/dist/Slider.js";` |
| Step Input | `ui5-step-input` | `import "@ui5/webcomponents/dist/StepInput.js";` |
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"prerelease": "node ./.github/actions/pre-release.js"
},
"devDependencies": {
"chromedriver": "^91.0.0",
"command-line-args": "^5.1.1",
"cross-env": "^7.0.3",
"glob-promise": "^4.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/main/bundle.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import Panel from "./dist/Panel.js";
import RadioButton from "./dist/RadioButton.js";
import ResponsivePopover from "./dist/ResponsivePopover.js";
import SegmentedButton from "./dist/SegmentedButton.js";
import SegmentedButtonItem from "./dist/SegmentedButtonItem.js";
import Select from "./dist/Select.js";
import Slider from "./dist/Slider.js";
import StepInput from "./dist/StepInput.js";
Expand Down
15 changes: 11 additions & 4 deletions packages/main/src/SegmentedButton.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<div
<ul
@click="{{_onclick}}"
@keydown="{{_onkeydown}}"
@keyup="{{_onkeyup}}"
@focusin="{{_onfocusin}}"
class="ui5-segmented-button-root"
role="group"
role="listbox"
dir="{{effectiveDir}}"
aria-roledescription="{{ariaDescription}}"
aria-multiselectable="true"
aria-describedby="{{_id}}-invisibleText"
aria-roledescription={{ariaDescription}}
>
<slot></slot>
</div>

<span id="{{_id}}-invisibleText" class="ui5-hidden-text">{{ariaDescribedBy}}</span>

</ul>
45 changes: 38 additions & 7 deletions packages/main/src/SegmentedButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js";
import { renderFinished } from "@ui5/webcomponents-base/dist/Render.js";
import { isIE } from "@ui5/webcomponents-base/dist/Device.js";
import { SEGMENTEDBUTTON_ARIA_DESCRIPTION } from "./generated/i18n/i18n-defaults.js";
import ToggleButton from "./ToggleButton.js";
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
import { SEGMENTEDBUTTON_ARIA_DESCRIPTION, SEGMENTEDBUTTON_ARIA_DESCRIBEDBY } from "./generated/i18n/i18n-defaults.js";
import SegmentedButtonItem from "./SegmentedButtonItem.js";

// Template
import SegmentedButtonTemplate from "./generated/templates/SegmentedButtonTemplate.lit.js";
Expand All @@ -26,11 +27,11 @@ const metadata = {
slots: /** @lends sap.ui.webcomponents.main.SegmentedButton.prototype */ {

/**
* Defines the buttons of component.
* Defines the buttons of <code>ui5-segmented-button</code>.
* <br><br>
* <b>Note:</b> Multiple buttons are allowed.
* <br><br>
* <b>Note:</b> Use the <code>ui5-toggle-button</code> for the intended design.
* <b>Note:</b> Use the <code>ui5-segmented-button-item</code> for the intended design.
terezamch marked this conversation as resolved.
Show resolved Hide resolved
* @type {sap.ui.webcomponents.main.IButton[]}
* @slot buttons
* @public
Expand Down Expand Up @@ -78,6 +79,7 @@ const metadata = {
* @extends sap.ui.webcomponents.base.UI5Element
* @tagname ui5-segmented-button
* @since 1.0.0-rc.6
* @appenddocs SegmentedButtonItem
* @public
*/
class SegmentedButton extends UI5Element {
Expand All @@ -98,7 +100,7 @@ class SegmentedButton extends UI5Element {
}

static get dependencies() {
return [ToggleButton];
return [SegmentedButtonItem];
}

static async onDefine() {
Expand Down Expand Up @@ -129,6 +131,13 @@ class SegmentedButton extends UI5Element {
}

onBeforeRendering() {
const buttons = this.getSlottedNodes("buttons");

buttons.forEach((item, index, arr) => {
item.posInSet = index + 1;
item.sizeOfSet = arr.length;
});

this.normalizeSelection();
}

Expand Down Expand Up @@ -172,7 +181,7 @@ class SegmentedButton extends UI5Element {
}
}

_onclick(event) {
_selectButton(event) {
if (event.target.disabled || event.target === this.getDomRef()) {
return;
}
Expand All @@ -193,6 +202,24 @@ class SegmentedButton extends UI5Element {
return this;
}

_onclick(event) {
this._selectButton(event);
}

_onkeydown(event) {
if (isEnter(event)) {
this._selectButton(event);
} else if (isSpace(event)) {
event.preventDefault();
}
}

_onkeyup(event) {
if (isSpace(event)) {
this._selectButton(event);
}
}

_onfocusin(event) {
// If the component was previously focused,
// update the ItemNavigation to sync butons` tabindex values
Expand Down Expand Up @@ -237,13 +264,17 @@ class SegmentedButton extends UI5Element {
* Currently selected button.
*
* @readonly
* @type { ui5-toggle-button }
* @type { ui5-segmented-button-item }
terezamch marked this conversation as resolved.
Show resolved Hide resolved
* @public
*/
get selectedButton() {
return this._selectedButton;
}

get ariaDescribedBy() {
return this.i18nBundle.getText(SEGMENTEDBUTTON_ARIA_DESCRIBEDBY);
}

get ariaDescription() {
return this.i18nBundle.getText(SEGMENTEDBUTTON_ARIA_DESCRIPTION);
}
Expand Down
42 changes: 42 additions & 0 deletions packages/main/src/SegmentedButtonItem.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<li
role="option"
aria-roledescription="{{ariaDescription}}"
aria-posinset="{{posInSet}}"
aria-setsize="{{sizeOfSet}}"
aria-selected="{{pressed}}"
class="ui5-button-root"
aria-disabled="{{disabled}}"
data-sap-focus-ref
{{> ariaPressed}}
dir="{{effectiveDir}}"
@focusout={{_onfocusout}}
@focusin={{_onfocusin}}
@click={{_onclick}}
@mousedown={{_onmousedown}}
@mouseup={{_onmouseup}}
@keydown={{_onkeydown}}
@keyup={{_onkeyup}}
@touchstart="{{_ontouchstart}}"
@touchend="{{_ontouchend}}"
tabindex={{tabIndexValue}}
aria-label="{{ariaLabelText}}"
title="{{accInfo.title}}"
>
{{#if icon}}
<ui5-icon
class="ui5-button-icon"
name="{{icon}}"
part="icon"
?show-tooltip={{showIconTooltip}}
></ui5-icon>
{{/if}}

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

</li>

{{#*inline "ariaPressed"}}{{/inline}}
121 changes: 121 additions & 0 deletions packages/main/src/SegmentedButtonItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import SegmentedButtonItemTemplate from "./generated/templates/SegmentedButtonItemTemplate.lit.js";
import ToggleButton from "./ToggleButton.js";
import ButtonDesign from "./types/ButtonDesign.js";

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

/**
* @public
*/
const metadata = {
tag: "ui5-segmented-button-item",
properties: /** @lends sap.ui.webcomponents.main.SegmentedButtonItem.prototype */ {
/**
* <b>Note:</b> The property is inherited and not supported. If set, it won't take any effect.
*
* @public
*/
design: {
type: ButtonDesign,
defaultValue: ButtonDesign.Default,
},

/**
* <b>Note:</b> The property is inherited and not supported. If set, it won't take any effect.
*
* @public
*/
iconEnd: {
type: Boolean,
},

/**
* <b>Note:</b> The property is inherited and not supported. If set, it won't take any effect.
*
* @public
*/
iconSize: {
type: String,
defaultValue: undefined,
},

/**
* <b>Note:</b> The property is inherited and not supported. If set, it won't take any effect.
*
* @public
*/
submits: {
type: Boolean,
},

/**
* <b>Note:</b> The property is inherited and not supported. If set, it won't take any effect.
*
* @public
*/
pressed: {
terezamch marked this conversation as resolved.
Show resolved Hide resolved
type: Boolean,
},

/**
* Defines the index of the item inside of the SegmentedButton.
*
* @private
* @type {String}
*/
posInSet: {
type: String,
},

/**
* Defines how many items are inside of the SegmentedButton.
*
* @private
* @type {String}
*/
sizeOfSet: {
type: String,
},
},
};

/**
* @class
*
*<h3 class="comment-api-title">Overview</h3>
*
* Users can use the <code>ui5-segmented-button-item</code> as part of a <code>ui5-segmented-button</code>.
* <br><br>
* Clicking or tapping on a <code>ui5-segmented-button-item</code> changes its state to <code>pressed</code>.
* The button 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
* <code>ui5-segmented-button-item</code>.
*
* <h3>ES6 Module Import</h3>
*
* <code>import "@ui5/webcomponents/dist/SegmentedButtonItem";</code>
*
* @constructor
* @author SAP SE
* @alias sap.ui.webcomponents.main.SegmentedButtonItem
* @extends Button
* @tagname ui5-segmented-button-item
* @public
*/
class SegmentedButtonItem extends ToggleButton {
static get metadata() {
return metadata;
}

static get template() {
return SegmentedButtonItemTemplate;
}

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

SegmentedButtonItem.define();

export default SegmentedButtonItem;
8 changes: 7 additions & 1 deletion packages/main/src/i18n/messagebundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ RATING_INDICATOR_TEXT=Rating Indicator
RESPONSIVE_POPOVER_CLOSE_DIALOG_BUTTON=Decline

#XACT: ARIA description for the segmented button
SEGMENTEDBUTTON_ARIA_DESCRIPTION=Segmented button
SEGMENTEDBUTTON_ARIA_DESCRIPTION=Segmented button group

#XACT: ARIA described by for the segmented button
SEGMENTEDBUTTON_ARIA_DESCRIBEDBY=Press SPACE or ENTER to select an item

#XACT: ARIA description for the segmented button item
SEGMENTEDBUTTONITEM_ARIA_DESCRIPTION=Segmented button

#XACT: ARIA description for slider handle
SLIDER_ARIA_DESCRIPTION=Slider handle
Expand Down
Loading