Skip to content

Commit f08715b

Browse files
committed
feat(range): add hover part for knob-handle, knob and pin
1 parent 6c5bfac commit f08715b

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

core/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,7 @@ ion-range,css-prop,--pin-color,md
14761476
ion-range,part,bar
14771477
ion-range,part,bar-active
14781478
ion-range,part,focused
1479+
ion-range,part,hover
14791480
ion-range,part,knob
14801481
ion-range,part,knob-a
14811482
ion-range,part,knob-b

core/src/components/range/range.tsx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ import type {
5050
* @part knob-b - The visual knob element for the second knob. Only available when `dualKnobs` is `true`.
5151
* @part knob-lower - The visual knob element for the lower knob. Only available when `dualKnobs` is `true`.
5252
* @part knob-upper - The visual knob element for the upper knob. Only available when `dualKnobs` is `true`.
53-
* @part pressed - Added to the knob-handle, knob, and pin that is currently being pressed to drag. Only one set has this part at a time.
54-
* @part focused - Added to the knob-handle, knob, and pin that currently has focus. Only one set has this part at a time.
53+
* @part pressed - Added to the knob-handle, knob, and pin that is currently being pressed to drag. Only one set has this part at a time when `dualKnobs` is `true`.
54+
* @part focused - Added to the knob-handle, knob, and pin that currently has focus. Only one set has this part at a time when `dualKnobs` is `true`.
55+
* @part hover - Added to the knob-handle, knob, and pin when the knob has hover. Only one set has this part at a time.
5556
*/
5657
@Component({
5758
tag: 'ion-range',
@@ -79,8 +80,9 @@ export class Range implements ComponentInterface {
7980

8081
@State() private ratioA = 0;
8182
@State() private ratioB = 0;
82-
@State() private pressedKnob: KnobName;
8383
@State() private focusedKnob: KnobName;
84+
@State() private hoveredKnob: KnobName;
85+
@State() private pressedKnob: KnobName;
8486

8587
/**
8688
* The color to use from your application's color palette.
@@ -697,6 +699,14 @@ export class Range implements ComponentInterface {
697699
}, 0);
698700
};
699701

702+
private onKnobMouseEnter = (knob: KnobName) => {
703+
this.hoveredKnob = knob;
704+
};
705+
706+
private onKnobMouseLeave = () => {
707+
this.hoveredKnob = undefined;
708+
};
709+
700710
/**
701711
* Returns true if content was passed to the "start" slot
702712
*/
@@ -722,6 +732,7 @@ export class Range implements ComponentInterface {
722732
step,
723733
handleKeyboard,
724734
focusedKnob,
735+
hoveredKnob,
725736
pressedKnob,
726737
disabled,
727738
pin,
@@ -869,8 +880,9 @@ export class Range implements ComponentInterface {
869880
knob: 'A',
870881
position: this.dualKnobs ? (this.ratioA <= this.ratioB ? 'lower' : 'upper') : 'lower',
871882
dualKnobs: this.dualKnobs,
872-
pressed: pressedKnob === 'A',
873883
focused: focusedKnob === 'A',
884+
hovered: hoveredKnob === 'A',
885+
pressed: pressedKnob === 'A',
874886
value: this.valA,
875887
ratio: this.ratioA,
876888
pin,
@@ -882,15 +894,18 @@ export class Range implements ComponentInterface {
882894
inheritedAttributes,
883895
onKnobFocus: this.onKnobFocus,
884896
onKnobBlur: this.onKnobBlur,
897+
onKnobMouseEnter: this.onKnobMouseEnter,
898+
onKnobMouseLeave: this.onKnobMouseLeave,
885899
})}
886900

887901
{this.dualKnobs &&
888902
renderKnob(rtl, {
889903
knob: 'B',
890904
position: this.ratioB <= this.ratioA ? 'lower' : 'upper',
891905
dualKnobs: this.dualKnobs,
892-
pressed: pressedKnob === 'B',
893906
focused: focusedKnob === 'B',
907+
hovered: hoveredKnob === 'B',
908+
pressed: pressedKnob === 'B',
894909
value: this.valB,
895910
ratio: this.ratioB,
896911
pin,
@@ -902,6 +917,8 @@ export class Range implements ComponentInterface {
902917
inheritedAttributes,
903918
onKnobFocus: this.onKnobFocus,
904919
onKnobBlur: this.onKnobBlur,
920+
onKnobMouseEnter: this.onKnobMouseEnter,
921+
onKnobMouseLeave: this.onKnobMouseLeave,
905922
})}
906923
</div>
907924
);
@@ -991,12 +1008,15 @@ interface RangeKnob {
9911008
disabled: boolean;
9921009
pressed: boolean;
9931010
focused: boolean;
1011+
hovered: boolean;
9941012
pin: boolean;
9951013
pinFormatter: PinFormatter;
9961014
inheritedAttributes: Attributes;
9971015
handleKeyboard: (name: KnobName, isIncrease: boolean) => void;
9981016
onKnobFocus: (knob: KnobName) => void;
9991017
onKnobBlur: () => void;
1018+
onKnobMouseEnter: (knob: KnobName) => void;
1019+
onKnobMouseLeave: () => void;
10001020
}
10011021

10021022
const renderKnob = (
@@ -1012,12 +1032,15 @@ const renderKnob = (
10121032
disabled,
10131033
pressed,
10141034
focused,
1035+
hovered,
10151036
pin,
10161037
handleKeyboard,
10171038
pinFormatter,
10181039
inheritedAttributes,
10191040
onKnobFocus,
10201041
onKnobBlur,
1042+
onKnobMouseEnter,
1043+
onKnobMouseLeave,
10211044
}: RangeKnob
10221045
) => {
10231046
const start = rtl ? 'right' : 'left';
@@ -1049,6 +1072,8 @@ const renderKnob = (
10491072
}}
10501073
onFocus={() => onKnobFocus(knob)}
10511074
onBlur={onKnobBlur}
1075+
onMouseEnter={() => onKnobMouseEnter(knob)}
1076+
onMouseLeave={onKnobMouseLeave}
10521077
class={{
10531078
'range-knob-handle': true,
10541079
'range-knob-handle-a': knob === 'A',
@@ -1068,6 +1093,7 @@ const renderKnob = (
10681093
dualKnobs && position === 'upper' && 'knob-handle-upper',
10691094
pressed && 'pressed',
10701095
focused && 'focused',
1096+
hovered && 'hover',
10711097
]
10721098
.filter(Boolean)
10731099
.join(' ')}
@@ -1093,6 +1119,7 @@ const renderKnob = (
10931119
dualKnobs && position === 'upper' && 'pin-upper',
10941120
pressed && 'pressed',
10951121
focused && 'focused',
1122+
hovered && 'hover',
10961123
]
10971124
.filter(Boolean)
10981125
.join(' ')}
@@ -1111,6 +1138,7 @@ const renderKnob = (
11111138
dualKnobs && position === 'upper' && 'knob-upper',
11121139
pressed && 'pressed',
11131140
focused && 'focused',
1141+
hovered && 'hover',
11141142
]
11151143
.filter(Boolean)
11161144
.join(' ')}

0 commit comments

Comments
 (0)