Skip to content

Commit

Permalink
Mouse Event
Browse files Browse the repository at this point in the history
  • Loading branch information
Syeda-Azim committed Jul 17, 2024
1 parent 226f6a0 commit 4254623
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
15 changes: 0 additions & 15 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,12 @@ <h2>Seek bar with max/min</h2>
document.addEventListener('hovering-move', (e) => {
document.getElementById('hoverValue').value = Math.round(e.target.hoverValue);
});

function getMinMaxValue() {
const seekBar = document.querySelector('d2l-seek-bar');
document.getElementById('maxInput').value = seekBar.max;
document.getElementById('minInput').value = seekBar.min;
document.getElementById('ratioInput').value = seekBar.ratio;
}

document.addEventListener('DOMContentLoaded', () => {
getMinMaxValue();
});

</script>
<d2l-seek-bar id="seekBar" value="0"></d2l-seek-bar><br>
<label>Hovering <input id="hoveringValue" readonly=""></label><br>
<label>Dragging <input id="dragValue" readonly=""></label><br>
<label>Immediate Value <input id="immediateValue" type="number" readonly=""></label><br>
<label>Hover Value <input id="hoverValue" type="number" readonly=""></label><br>
<label>Max <input id="maxInput" type="number"></label><br>
<label>Min <input id="minInput" type="number"></label><br>
<label>Ratio <input id="ratioInput" type="number"></label><br>
</d2l-demo-snippet>

<h2>Seek bar with full width</h2>
Expand Down
18 changes: 12 additions & 6 deletions seekBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ class SeekBar extends InternalDynamicLocalizeMixin(RtlMixin(LitElement)) {
console.log('Mouse UP Event from window listener');

Check failure on line 159 in seekBar.js

View workflow job for this annotation

GitHub Actions / Lint/Test

Unexpected console statement
this._barUp();
});

window.addEventListener('mousemove', (e) => {
console.log('Mouse MOVE Event from window listener');

Check failure on line 164 in seekBar.js

View workflow job for this annotation

GitHub Actions / Lint/Test

Unexpected console statement
this._onTrack(e);
});
}

render() {
Expand All @@ -179,7 +184,6 @@ class SeekBar extends InternalDynamicLocalizeMixin(RtlMixin(LitElement)) {
.max="${this.max}"
.value="${this.immediateValue}"
@mousedown="${this._barDown}"
role="slider"
aria-label="${this.localize('seekBarProgress')}"
aria-orientation="${this.vertical ? 'vertical' : 'horizontal'}"
Expand Down Expand Up @@ -238,7 +242,7 @@ class SeekBar extends InternalDynamicLocalizeMixin(RtlMixin(LitElement)) {
event.preventDefault();
this.focus();

this.addEventListener('mousemove', this._onTrack);
//this.addEventListener('mousemove', this._onTrack);
}

_barUp() {
Expand Down Expand Up @@ -305,7 +309,7 @@ class SeekBar extends InternalDynamicLocalizeMixin(RtlMixin(LitElement)) {

_onHostMove(e) {
console.log('HOST Move');

Check failure on line 311 in seekBar.js

View workflow job for this annotation

GitHub Actions / Lint/Test

Unexpected console statement
if (this.hovering) {
if (this.hovering || this.dragging) {

const rect = this.shadowRoot.getElementById('knobContainer').getBoundingClientRect();
const mousePosition = this.vertical ? rect.bottom - e.clientY : e.clientX - rect.left;
Expand All @@ -332,9 +336,11 @@ class SeekBar extends InternalDynamicLocalizeMixin(RtlMixin(LitElement)) {
}

_onTrack(event) {
this.dispatchEvent(new CustomEvent('position-change', { bubbles: true, composed: true }));
event.stopPropagation();
this._track(event);
if(this.dragging){

Check failure on line 339 in seekBar.js

View workflow job for this annotation

GitHub Actions / Lint/Test

Expected space(s) after "if"

Check failure on line 339 in seekBar.js

View workflow job for this annotation

GitHub Actions / Lint/Test

Missing space before opening brace
this.dispatchEvent(new CustomEvent('position-change', { bubbles: true, composed: true }));
event.stopPropagation();
this._track(event);

Check failure on line 342 in seekBar.js

View workflow job for this annotation

GitHub Actions / Lint/Test

Trailing spaces not allowed
}
}

_positionKnob(ratio) {
Expand Down

0 comments on commit 4254623

Please sign in to comment.