Skip to content

Commit

Permalink
Add workaround for min price range
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro-K committed Dec 4, 2024
1 parent c7e2db7 commit 826ecd6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ import PropTypes from 'prop-types';
import './PriceFilter.scss';
import { _ } from '@evershop/evershop/src/lib/locale/translate';

if (typeof document !== 'undefined')
{
document.addEventListener('DOMContentLoaded', function () {
const input = document.querySelector('input.min');
const part = (input.value - input.min) / (input.max - input.min);
const div = input.nextElementSibling;
const x = part * (input.getBoundingClientRect().width - div.getBoundingClientRect().width);
div.style.left = x + 'px';
});
}

function minOnMouseOut (e) {
e.target.style.zIndex = 0;
}

function mindivOnMouseOver(e) {
e.target.previousSibling.style.zIndex = 2;
}

export function PriceFilter({
priceRange: { min: minPrice, max: maxPrice },
currentFilters,
Expand Down Expand Up @@ -113,6 +132,11 @@ export function PriceFilter({
firstRender.current = false;
const { value } = e.target;
if (direction === 'min') {
const part = (e.target.value - e.target.min) / (e.target.max - e.target.min);
const div = e.target.nextElementSibling;
const x = part * (e.target.getBoundingClientRect().width - div.getBoundingClientRect().width);
div.style.left = x + 'px';

if (value > to - 5) {
setFrom(to - 5);
} else {
Expand Down Expand Up @@ -149,6 +173,10 @@ export function PriceFilter({
max={maxPrice}
value={from}
onChange={(e) => onChange(e, 'min')}
onMouseOut={(e) => minOnMouseOut(e)}
/>
<div className="mindiv"
onMouseOver={(e) => mindivOnMouseOver(e)}
/>
<div className="tooltip min">
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,20 @@
.price-filter .filter-item-title {
border-bottom: 0;
}

.min, .max {
&::-moz-range-track, &::-webkit-slider-runnable-track {
background: black;
height: 1px;
}
}

.mindiv {
width: 16px;
height: 16px;
position: absolute;
//border: 2px solid green;
box-sizing: border-box;
z-index: 1;
margin: 7px 1px;
}

0 comments on commit 826ecd6

Please sign in to comment.