From b1936ed17a4148dd84c035be3f288287b365a6e9 Mon Sep 17 00:00:00 2001 From: cchaos Date: Thu, 21 Jun 2018 16:18:06 -0400 Subject: [PATCH] Fixed tooltip position --- .../range/__snapshots__/range.test.js.snap | 14 ++++++---- src/components/form/range/_range.scss | 21 ++++++++------- src/components/form/range/range.js | 26 ++++++++++++------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/components/form/range/__snapshots__/range.test.js.snap b/src/components/form/range/__snapshots__/range.test.js.snap index 6964de2752a..6bba54015c9 100644 --- a/src/components/form/range/__snapshots__/range.test.js.snap +++ b/src/components/form/range/__snapshots__/range.test.js.snap @@ -238,7 +238,7 @@ exports[`EuiRange props ticks should render 1`] = ` exports[`EuiRange props value should render 1`] = `
- +
+ +
`; diff --git a/src/components/form/range/_range.scss b/src/components/form/range/_range.scss index 632f314c0e1..7ff2b8c405a 100644 --- a/src/components/form/range/_range.scss +++ b/src/components/form/range/_range.scss @@ -216,13 +216,6 @@ $euiRange__levelColors: ( } .euiRange__wrapper--hasTicks { - .euiRange, - .euiRange__levels, - .euiRange__range { - //width: calc(100% + #{$euiRangeThumbWidth}); - //margin-left: $euiRangeThumbWidth/2 * -1; - } - .euiRange { height: $euiFormControlHeight/2; /* 3 */ } @@ -254,6 +247,17 @@ $euiRange__levelColors: ( } } +.euiRange__valueWrapper { + // Keeps tooltip (value) aligned to percentage of actual slider + display: block; + position: absolute; + left: 0; + top: 0; + bottom: 0; + width: calc(100% - #{$euiRangeThumbWidth}); + margin-left: $euiRangeThumbWidth/2; +} + /* * Input Range Customization by browser */ @@ -273,7 +277,6 @@ $euiRange__levelColors: ( height: $euiFormControlHeight; appearance: none; background: transparent; // Otherwise white in Chrome - //margin: 0 $euiSizeS; width: 100%; // ensures the slider expands to fill flex display position: relative; z-index: $euiZLevel2; // stay above tick marks @@ -304,7 +307,7 @@ $euiRange__levelColors: ( background-color: $euiColorPrimary; } - ~ .euiRange__value { + ~ .euiRange__valueWrapper .euiRange__value { @include euiBottomShadow; &.euiRange__value--right { diff --git a/src/components/form/range/range.js b/src/components/form/range/range.js index fdf1f0ca4c9..6ba8717e77c 100644 --- a/src/components/form/range/range.js +++ b/src/components/form/range/range.js @@ -48,6 +48,7 @@ export const EuiRange = ({ 'euiRange__wrapper--hasTicks': showTicks, 'euiRange__wrapper--hasLevels': levels.length, 'euiRange__wrapper--hasRange': showRange, + 'euiRange__wrapper--hasValue': showValue, }, ); @@ -94,7 +95,7 @@ export const EuiRange = ({ } const inputWrapperStyle = {}; - let tickWidth; + let tickWidth; // TODO: Move to scope & change name let tickMarksNode; if (showTicks) { // Set the interval for which to show the tick marks @@ -108,17 +109,20 @@ export const EuiRange = ({ const ticksStyle = { margin: `0 ${tickWidthPercentage / -2}%` }; // Loop from min to max, creating ticks at each interval - // (adds 1 to max to ensure that the max tick is also included) - const sequence = range(min, max + 1, interval); + // (adds 1 to max to ensure that the max tick is also included) TODO: add more about +1 for length + const toBeInclusive = .000000001; + const sequence = range(min, max + toBeInclusive, interval); + console.log(sequence); // Calculate if any extra margin should be added to the inputWrapper // because of longer tick labels on the ends const minLength = String(sequence[0]).length; const maxLength = String(sequence[sequence.length - 1]).length; - if (minLength > 2) { + const lastTickIsMax = sequence[sequence.length - 1] === max; + if (lastTickIsMax && minLength > 2) { inputWrapperStyle.marginLeft = `${(minLength / 5)}em`; } - if (maxLength > 2) { + if (lastTickIsMax && maxLength > 2) { inputWrapperStyle.marginRight = `${(maxLength / 5)}em`; } @@ -180,8 +184,8 @@ export const EuiRange = ({ let valueNode; if (showValue) { // Calculate the left position based on value - // Must be between 0-100% const decimal = (value - min) / rangeTotal; + // Must be between 0-100% let valuePosition = decimal <= 1 ? decimal : 1; valuePosition = valuePosition >= 0 ? valuePosition : 0; @@ -201,9 +205,11 @@ export const EuiRange = ({ ); valueNode = ( - - {value} - +
+ + {value} + +
); } @@ -226,10 +232,12 @@ export const EuiRange = ({ style={style} {...rest} /> + {valueNode} {rangeNode} {tickMarksNode} {levelsNode} + {maxLabelNode}