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-slider, ui5-range-slider): add input as a tooltip #9547

Merged
merged 57 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d071fe9
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Jul 23, 2024
76b9df2
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Jul 24, 2024
fc4c145
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Jul 25, 2024
f54169f
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Jul 25, 2024
8778869
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Jul 25, 2024
f1dc9c7
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Jul 26, 2024
b32dfdd
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Jul 31, 2024
5e2f4b4
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Jul 31, 2024
3f0a96d
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 12, 2024
9389faf
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 12, 2024
917a8d9
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 12, 2024
011ccc9
Merge branch 'slider-input-tooltip' of https://github.com/SAP/ui5-web…
ndeshev Aug 12, 2024
82fca2e
Merge branch 'main' into slider-input-tooltip
ndeshev Aug 12, 2024
4355fc2
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 12, 2024
1334ae7
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 12, 2024
f01cb06
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 14, 2024
a8e0808
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 14, 2024
791c035
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 16, 2024
a02e5c4
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 20, 2024
c5c45a2
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 20, 2024
13d14ae
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 20, 2024
bc0d25b
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 22, 2024
5de1e4d
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 23, 2024
459d15a
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 23, 2024
f7e2915
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 23, 2024
ecce66e
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 25, 2024
ba84adc
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 25, 2024
4da66e6
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 25, 2024
78b74ea
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 26, 2024
ca45659
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 26, 2024
bb5df87
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 26, 2024
049b922
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Aug 26, 2024
37f145f
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 10, 2024
715da42
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 10, 2024
5735d0c
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 13, 2024
3b34a23
feat(ui5-slider, ui5-range-slider): fix aria-describedby attribute fo…
ndeshev Sep 13, 2024
11e343e
feat(ui5-slider, ui5-range-slider): fix property getter typo
ndeshev Sep 13, 2024
96afa78
feat(ui5-slider, ui5-range-slider): add event firing
ndeshev Sep 14, 2024
125bf06
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 15, 2024
65c7588
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 15, 2024
a39435c
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 16, 2024
e6793b8
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 16, 2024
c471639
fix(ui5-multi-combobox): fix aria-describedby token count
Okiana Sep 17, 2024
33071a6
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 18, 2024
01e69ac
Merge branch 'mcb-ariadescribed' of https://github.com/SAP/ui5-webcom…
ndeshev Sep 18, 2024
6f2875e
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 25, 2024
6006209
Merge branch 'main' into slider-input-tooltip
ndeshev Sep 25, 2024
3342e70
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 25, 2024
713bd57
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 26, 2024
edb2c98
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Sep 26, 2024
9773346
Merge branch 'main' into slider-input-tooltip
ndeshev Sep 26, 2024
b1f8d3a
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Oct 1, 2024
5743e7d
Merge branch 'main' into slider-input-tooltip
ndeshev Oct 7, 2024
2f1bd2a
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Oct 9, 2024
7720fa8
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Oct 9, 2024
a2448c7
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Oct 10, 2024
0e288a3
feat(ui5-slider, ui5-range-slider): add input as a tooltip
ndeshev Oct 14, 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
97 changes: 62 additions & 35 deletions packages/main/src/RangeSlider.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,76 @@
{{/inline}}

{{#*inline "handles"}}
<div class="ui5-slider-handle ui5-slider-handle--start"
part="handle"
style="{{styles.startHandle}}"
@focusin="{{_onfocusin}}"
@focusout="{{_onfocusout}}"
role="slider"
tabindex="{{_tabIndex}}"
aria-orientation="horizontal"
aria-valuemin="{{min}}"
aria-valuemax="{{max}}"
aria-valuenow="{{startValue}}"
aria-labelledby="{{_ariaLabelledByStartHandleRefs}}"
aria-disabled="{{_ariaDisabled}}"
>
<ui5-icon name="direction-arrows" mode="Decorative" slider-icon></ui5-icon>
<div class="ui5-slider-handle-container" style="{{styles.startHandle}}" part="handle-container">

<div class="ui5-slider-handle ui5-slider-handle--start"
part="handle"
style="{{styles.startHandle}}"
@focusin="{{_onfocusin}}"
@focusout="{{_onfocusout}}"
role="slider"
tabindex="{{_tabIndex}}"
aria-orientation="horizontal"
aria-valuemin="{{min}}"
aria-valuemax="{{max}}"
aria-valuenow="{{startValue}}"
aria-labelledby="{{_ariaLabelledByStartHandleRefs}}"
aria-disabled="{{_ariaDisabled}}"
>
<ui5-icon name="direction-arrows" slider-icon></ui5-icon>
ndeshev marked this conversation as resolved.
Show resolved Hide resolved
</div>

{{#if showTooltip}}
<div class="ui5-slider-tooltip ui5-slider-tooltip--start" style="{{styles.tooltip}}">
<div class="ui5-slider-tooltip ui5-slider-tooltip--start" style="{{styles.tooltip}}">
{{#if editableTooltip}}
<ui5-input
type="Number"
value="{{startValue}}"
accessible-name-ref="{{_ariaLabelledByInputRefs}}"
@focusout="{{_onInputFocusOut}}"
@keydown="{{_onInputKeydown}}"
data-sap-ui-start-value
tabindex="-1"
></ui5-input>
{{else}}
<span class="ui5-slider-tooltip-value">{{tooltipStartValue}}</span>
</div>
{{/if}}
</div>
{{/if}}
</div>

<div class="ui5-slider-handle ui5-slider-handle--end"
part="handle"
style="{{styles.endHandle}}"
@focusin="{{_onfocusin}}"
@focusout="{{_onfocusout}}"
role="slider"
tabindex="{{_tabIndex}}"
aria-orientation="horizontal"
aria-valuemin="{{min}}"
aria-valuemax="{{max}}"
aria-valuenow="{{endValue}}"
aria-labelledby="{{_ariaLabelledByEndHandleRefs}}"
aria-disabled="{{_ariaDisabled}}"
>
<ui5-icon name="direction-arrows" mode="Decorative" slider-icon></ui5-icon>
<div class="ui5-slider-handle-container" style="{{styles.endHandle}}" part="handle-container">
<div class="ui5-slider-handle ui5-slider-handle--end"
part="handle"
@focusin="{{_onfocusin}}"
@focusout="{{_onfocusout}}"
role="slider"
tabindex="{{_tabIndex}}"
aria-orientation="horizontal"
aria-valuemin="{{min}}"
aria-valuemax="{{max}}"
aria-valuenow="{{endValue}}"
aria-labelledby="{{_ariaLabelledByEndHandleRefs}}"
aria-disabled="{{_ariaDisabled}}"
>
<ui5-icon name="direction-arrows" slider-icon></ui5-icon>
</div>

{{#if showTooltip}}
<div class="ui5-slider-tooltip ui5-slider-tooltip--end" style="{{styles.tooltip}}">
<div class="ui5-slider-tooltip ui5-slider-tooltip--end" style="{{styles.tooltip}}">
{{#if editableTooltip}}
<ui5-input
type="Number"
value="{{endValue}}"
accessible-name-ref="{{_ariaLabelledByInputRefs}}"
@focusout="{{_onInputFocusOut}}"
@keydown="{{_onInputKeydown}}"
data-sap-ui-end-value
tabindex="-1"
></ui5-input>
{{else}}
<span class="ui5-slider-tooltip-value">{{tooltipEndValue}}</span>
</div>
{{/if}}
</div>
{{/if}}
</div>
{{/inline}}
79 changes: 70 additions & 9 deletions packages/main/src/RangeSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import {
import SliderBase from "./SliderBase.js";
import Icon from "./Icon.js";
import RangeSliderTemplate from "./generated/templates/RangeSliderTemplate.lit.js";
import Input from "./Input.js";

// Texts
import {
RANGE_SLIDER_ARIA_DESCRIPTION,
RANGE_SLIDER_START_HANDLE_DESCRIPTION,
RANGE_SLIDER_END_HANDLE_DESCRIPTION,
RANGE_SLIDER_TOOLTIP_INPUT_LABEL,
RANGE_SLIDER_TOOLTIP_INPUT_DESCRIPTION,
} from "./generated/i18n/i18n-defaults.js";

// Styles
Expand Down Expand Up @@ -88,7 +91,7 @@ type AffectedValue = "startValue" | "endValue";
languageAware: true,
formAssociated: true,
template: RangeSliderTemplate,
dependencies: [Icon],
dependencies: [Icon, Input],
styles: [SliderBase.styles, rangeSliderStyles],
})
class RangeSlider extends SliderBase implements IFormInputElement {
Expand Down Expand Up @@ -128,6 +131,8 @@ class RangeSlider extends SliderBase implements IFormInputElement {
_secondHandlePositionFromStart?: number;
_selectedRange?: number;
_reversedValues = false;
_lastValidStartValue: string;
_lastValidEndValue: string;

static i18nBundle: I18nBundle;

Expand All @@ -148,6 +153,8 @@ class RangeSlider extends SliderBase implements IFormInputElement {
super();
this._stateStorage.startValue = undefined;
this._stateStorage.endValue = undefined;
this._lastValidStartValue = this.min.toString();
this._lastValidEndValue = this.max.toString();
}

get tooltipStartValue() {
Expand Down Expand Up @@ -201,6 +208,8 @@ class RangeSlider extends SliderBase implements IFormInputElement {
*
*/
onBeforeRendering() {
this._updateInputValues();

if (this.startValue > this.endValue) {
const affectedValue = this._valueAffected === "startValue" ? "endValue" : "startValue";

Expand Down Expand Up @@ -278,7 +287,7 @@ class RangeSlider extends SliderBase implements IFormInputElement {
* Resets the stored Range Slider's initial values saved when it was first focused
* @private
*/
_onfocusout() {
_onfocusout(e: FocusEvent) {
if (this._isFocusing()) {
this._preventFocusOut();
return;
Expand All @@ -288,11 +297,16 @@ class RangeSlider extends SliderBase implements IFormInputElement {
this._startValueInitial = undefined;
this._endValueInitial = undefined;

if (this.showTooltip) {
if (this.showTooltip && !(e.relatedTarget as HTMLInputElement)?.hasAttribute("ui5-input")) {
this._tooltipVisibility = SliderBase.TOOLTIP_VISIBILITY.HIDDEN;
}
}

_onInputFocusOut(e: FocusEvent) {
this._tooltipVisibility = SliderBase.TOOLTIP_VISIBILITY.HIDDEN;
this._updateValueFromInput(e);
}

/**
* Handles keyup logic. If one of the handles came across the other
* swap the start and end values. Reset the affected value by the finished
Expand Down Expand Up @@ -428,7 +442,7 @@ class RangeSlider extends SliderBase implements IFormInputElement {
_onmousedown(e: TouchEvent | MouseEvent) {
// If step is 0 no interaction is available because there is no constant
// (equal for all user environments) quantitative representation of the value
if (this.disabled || this._effectiveStep === 0) {
if (this.disabled || this._effectiveStep === 0 || (e.target as HTMLElement).hasAttribute("ui5-input")) {
return;
}

Expand Down Expand Up @@ -483,7 +497,7 @@ class RangeSlider extends SliderBase implements IFormInputElement {
e.preventDefault();

// If 'step' is 0 no interaction is available as there is no constant quantitative representation of the value
if (this.disabled || this._effectiveStep === 0) {
if (this.disabled || this._effectiveStep === 0 || (e.target as HTMLElement).hasAttribute("ui5-input")) {
return;
}

Expand Down Expand Up @@ -524,7 +538,11 @@ class RangeSlider extends SliderBase implements IFormInputElement {
this.update(undefined, newValues[0], newValues[1]);
}

_handleUp() {
_handleUp(e: MouseEvent) {
if ((e.target as HTMLElement).hasAttribute("ui5-input")) {
return;
}

this._setAffectedValueByFocusedElement();
this._setAffectedValue(undefined);

Expand All @@ -540,6 +558,25 @@ class RangeSlider extends SliderBase implements IFormInputElement {
this._endValueAtBeginningOfAction = undefined;
}

_updateValueFromInput(e: Event) {
const ctor = this.constructor as typeof RangeSlider;

const input = e.target as HTMLInputElement;
const value = ctor.clipValue(parseFloat(input.value), this._effectiveMin, this._effectiveMax);
ndeshev marked this conversation as resolved.
Show resolved Hide resolved
const isValueValid = value >= this._effectiveMin && value <= this._effectiveMax;

if (!isValueValid) {
return;
}

if (input.hasAttribute("data-sap-ui-start-value")) {
this.startValue = value;
return;
}

this.endValue = value;
}

/**
* Determines where the press occured and which values of the Range Slider
* handles should be updated on further interaction.
Expand Down Expand Up @@ -749,6 +786,22 @@ class RangeSlider extends SliderBase implements IFormInputElement {
}
}

_updateInputValues() {
const startValueInput = this.shadowRoot!.querySelector("ui5-input[data-sap-ui-start-value]") as Input;
const endValueInput = this.shadowRoot!.querySelector("ui5-input[data-sap-ui-end-value]") as Input;

if (this.editableTooltip && startValueInput && endValueInput) {
const isStartValueValid = parseFloat(startValueInput.value) >= this.min && parseFloat(startValueInput.value) <= this.max;
const isEndValueValid = parseFloat(endValueInput.value) >= this.min && parseFloat(endValueInput.value) <= this.max;

startValueInput.value = startValueInput.value ? startValueInput.value : this._lastValidStartValue;
endValueInput.value = endValueInput.value ? endValueInput.value : this._lastValidEndValue;

this._lastValidStartValue = (!!startValueInput.value && isStartValueValid) ? startValueInput.value : this._lastValidStartValue;
this._lastValidEndValue = (!!endValueInput.value && isEndValueValid) ? endValueInput.value : this._lastValidEndValue;
}
}

/**
* Swaps the start and end values of the handles if one came accros the other:
* - If the start value is greater than the endValue swap them and their handles
Expand Down Expand Up @@ -830,15 +883,23 @@ class RangeSlider extends SliderBase implements IFormInputElement {
}

get _ariaLabelledByStartHandleRefs() {
return [`${this._id}-accName`, `${this._id}-startHandleDesc`].join(" ").trim();
return ["ui5-slider-accName", "ui5-slider-startHandleDesc"].join(" ").trim();
}

get _ariaLabelledByEndHandleRefs() {
return [`${this._id}-accName`, `${this._id}-endHandleDesc`].join(" ").trim();
return ["ui5-slider-accName", "ui5-slider-endHandleDesc"].join(" ").trim();
}

get _ariaLabelledByProgressBarRefs() {
ndeshev marked this conversation as resolved.
Show resolved Hide resolved
return [`${this._id}-accName`, `${this._id}-sliderDesc`].join(" ").trim();
return ["ui5-slider-accName", "ui5-slider-sliderDesc"].join(" ").trim();
ndeshev marked this conversation as resolved.
Show resolved Hide resolved
}

get _ariaLabelledByInputText() {
return RangeSlider.i18nBundle.getText(RANGE_SLIDER_TOOLTIP_INPUT_LABEL);
}

get _ariaDescribedByInputText() {
return RangeSlider.i18nBundle.getText(RANGE_SLIDER_TOOLTIP_INPUT_DESCRIPTION);
}

get styles() {
Expand Down
52 changes: 34 additions & 18 deletions packages/main/src/Slider.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,42 @@
{{/inline}}

{{#*inline "handles"}}
<div class="ui5-slider-handle"
style="{{styles.handle}}"
@focusout="{{_onfocusout}}"
@focusin="{{_onfocusin}}"
role="slider"
tabindex="{{_tabIndex}}"
aria-orientation="horizontal"
aria-valuemin="{{min}}"
aria-valuemax="{{max}}"
aria-valuenow="{{value}}"
aria-labelledby="{{_ariaLabelledByHandleRefs}}"
aria-disabled="{{_ariaDisabled}}"
data-sap-focus-ref
part="handle"
>
<ui5-icon mode="Decorative" "direction-arrows" part="icon-slider" slider-icon></ui5-icon>
<div class="ui5-slider-handle-container" style="{{styles.handle}}" part="handle-container">
<div class="ui5-slider-handle"
@focusout="{{_onfocusout}}"
@focusin="{{_onfocusin}}"
role="slider"
tabindex="{{_tabIndex}}"
aria-orientation="horizontal"
aria-valuemin="{{min}}"
aria-valuemax="{{max}}"
aria-valuenow="{{value}}"
aria-labelledby="{{_ariaLabelledByHandleRefs}}"
aria-disabled="{{_ariaDisabled}}"
aria-keyshortcuts="F2"
aria-describedby="{{_ariaDescribedByHandleRefs}}"

data-sap-focus-ref
part="handle"
>
<ui5-icon name="direction-arrows" part="icon-slider" slider-icon></ui5-icon>
</div>
{{#if showTooltip}}
<div class="ui5-slider-tooltip" style="{{styles.tooltip}}">
<div class="ui5-slider-tooltip" style="{{styles.tooltip}}">
{{#if editableTooltip}}
<ui5-input
value="{{value}}"
type="Number"
accessible-name-ref="{{_ariaLabelledByInputRefs}}"
@focusout="{{_onInputFocusOut}}"
@keydown="{{_onInputKeydown}}"
data-sap-ui-end-value
tabindex="-1"
></ui5-input>
{{else}}
<span class="ui5-slider-tooltip-value">{{tooltipValue}}</span>
</div>
{{/if}}
</div>
{{/if}}
</div>
{{/inline}}
Loading
Loading