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

🐛 Fix custom hd range bullets precision #1189

Merged
merged 5 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 18 additions & 8 deletions src/components/form/HdRange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,33 @@
class="range__progress"
/>
</div>
<div v-if="displayStepBullets || stepBullets.length" class="range__steps">
<template v-for="(stepValue, stepIndex) in stepsAmount">
<template v-if="displayStepBullets">
<div class="range__steps">
<button
v-if="displayStepBullets || isStepBulletVisible(stepValue)"
v-for="(_, stepIndex) in stepsAmount"
:key="stepIndex"
type="button"
class="range__step"
@click="onStepClick(stepIndex)"
>
<p v-if="labels[stepIndex]" class="range__step-label" v-html="labels[stepIndex]" />
</button>
</div>
</template>
<template v-else-if="stepBullets.length">
<div class="range__steps">
<button
v-for="(stepValue, stepIndex) in stepBullets"
:key="stepValue"
type="button"
class="range__step"
@click="onStepClick(stepIndex)"
:style="customStepBulletOffset(stepValue)"
>
<p v-if="labels[stepIndex]" class="range__step-label" v-html="labels[stepIndex]" />
</button>
</template>
</div>
</div>
</template>
<div class="range__thumb" ref="thumb">
<div v-if="displayTooltip" class="range__tooltip">
<img :src="tooltipBackground" class="range__tooltip__background" />
Expand Down Expand Up @@ -209,9 +222,6 @@ export default {
blurHandler() {
this.isActive = false;
},
isStepBulletVisible(value) {
return this.stepBullets.includes(value);
},
customStepBulletOffset(value) {
if (!this.stepBullets.length) return {}; // Early return standard bullets
const stepPosition = this.stepBullets.indexOf(value);
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/components/form/HdRange.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,22 @@ describe('HdRange', () => {
});

it('renders custom step bullets', () => {
const wrapper = stepBulletsWrapperBuilder();
let wrapper = stepBulletsWrapperBuilder();
expect(wrapper.findAll(VISIBLE_STEP_BULLETS_SELECTOR).length).toBe(5);

wrapper = stepBulletsWrapperBuilder({
props: {
name: 'storybook',
min: 8,
max: 12,
step: 0.5,
value: 9.5,
labels: [],
displayStepBullets: false,
stepBullets: [8, 9, 9.5, 10, 11, 12],
},
});
expect(wrapper.findAll(VISIBLE_STEP_BULLETS_SELECTOR).length).toBe(6);
});
it('updates value to closest step bullet', async () => {
const wrapper = stepBulletsWrapperBuilder();
Expand Down
Loading