Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 0 additions & 7 deletions packages/main/src/RangeSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,13 +953,6 @@ class RangeSlider extends SliderBase implements IFormInputElement {
endHandle: {
[this.directionStart]: `${this._secondHandlePositionFromStart!}%`,
},
label: {
"width": `${this._labelWidth}%`,
},
labelContainer: {
"width": `100%`,
[this.directionStart]: `-${this._labelWidth / 2}%`,
},
};
}
}
Expand Down
7 changes: 0 additions & 7 deletions packages/main/src/Slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,6 @@ class Slider extends SliderBase implements IFormInputElement {
handle: {
[this.directionStart]: `${this._handlePositionFromStart}%`,
},
label: {
"width": `${this._labelWidth}%`,
},
labelContainer: {
"width": `100%`,
[this.directionStart]: `-${this._labelWidth / 2}%`,
},
};
}

Expand Down
21 changes: 11 additions & 10 deletions packages/main/src/SliderBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,6 @@ abstract class SliderBase extends UI5Element {

_handleActionKeyPress(e: Event) {} // eslint-disable-line

// used in base template, but implemented in subclasses
abstract styles: {
label: Record<string, string>,
labelContainer: Record<string, string>,
};

abstract tickmarksObject: Array<boolean>;
abstract _ariaLabelledByText: string;

Expand Down Expand Up @@ -395,21 +389,28 @@ abstract class SliderBase extends UI5Element {
// In such case the labels must correspond to the tickmarks, only the first and the last one should exist.
if (spaceBetweenTickmarks < SliderBase.MIN_SPACE_BETWEEN_TICKMARKS) {
this._hiddenTickmarks = true;
this._labelsOverlapping = true;
} else {
this._hiddenTickmarks = false;
}

if (this.labelInterval <= 0 || this._hiddenTickmarks) {
this._labelsOverlapping = true;
return;
}

// Check if there are any overlapping labels.
// If so - only the first and the last one should be visible
const labelItems = this.shadowRoot!.querySelectorAll(".ui5-slider-labels li");
this._labelsOverlapping = [...labelItems].some(label => label.scrollWidth > label.clientWidth);
}

const remInPx = parseFloat(getComputedStyle(document.documentElement).fontSize); // calculate 1 rem in pixcels
const childWidthPx = 2 * remInPx; // as specified label must be 2 rems so calculate one child width in pixcels

const labelItemsParent = this.shadowRoot!.querySelector(".ui5-slider-labels") as HTMLElement;

const labelItemsSumWidth = this._labels.length * childWidthPx; // all labels width
const labelItemsParentWidth = labelItemsParent.clientWidth; // label parent width

this._labelsOverlapping = labelItemsParentWidth < labelItemsSumWidth;
}
/**
* Called when the user starts interacting with the slider.
* After a down event on the slider root, listen for move events on window, so the slider value
Expand Down
5 changes: 2 additions & 3 deletions packages/main/src/SliderBaseTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ export default function SliderBaseTemplate(this: SliderBase, hooks?: {
"ui5-slider-labels": true,
"ui5-slider-hidden-labels": this._labelsOverlapping,
}}
style={this.styles.labelContainer}
>
{this._labels.map(l =>
<li style={this.styles.label}>{l}</li>
{this._labels.map(l =>
<li data-counter={l}></li>
)}
</ul>
}
Expand Down
30 changes: 20 additions & 10 deletions packages/main/src/themes/SliderBase.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

.ui5-slider-tickmarks li {
height: var(--_ui5_slider_tickmark_height);
border-inline-start: 1px solid var(--_ui5_slider_tickmark_bg);
border-inline-start: 0.0625rem solid var(--_ui5_slider_tickmark_bg);
}

.ui5-slider-handle {
Expand Down Expand Up @@ -203,28 +203,38 @@
margin: 0;
padding: 0;
white-space: nowrap;
height: 1rem;
width: 100%;
display: flex;
justify-content: space-between;
}

.ui5-slider-labels li {
position: relative;
position: relative;
list-style: none;
padding-top: 0.3125rem;
height: 1rem;
margin: 0;
text-align: center;
display: inline-block;
color: var(--_ui5_slider_label_color);
font-family: var(--sapFontFamily);
font-size: var(--_ui5_slider_label_fontsize);
padding-top: 0;
box-sizing: border-box;
display: inline-flex;
justify-content: center;
align-items: center;
vertical-align: top;
width: 0.0625rem;
visibility: hidden;
}

.ui5-slider-labels li::after {
content: attr(data-counter);
position: absolute;
top: 0;
visibility: visible;
display: inline-block;
width: 2rem;
color: var(--_ui5_slider_label_color);
transform: translateX(-50%);
}

.ui5-slider-hidden-labels li:not(:first-child):not(:last-child) {
.ui5-slider-hidden-labels li:not(:first-child):not(:last-child)::after {
visibility: hidden;
}

Expand Down
Loading