-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make number input "scroll updatable"
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Modifier from 'ember-modifier'; | ||
import type DefaultSignature from 'ember-modifier'; | ||
import type { ArgsFor } from 'ember-modifier'; | ||
|
||
import type { CalciteInputText } from '@esri/calcite-components/dist/components/calcite-input-text'; | ||
import { registerDestructor } from '@ember/destroyable'; | ||
import { action } from '@ember/object'; | ||
|
||
import type Owner from '@ember/owner'; | ||
|
||
export default class ThreeRendererModifier extends Modifier<DefaultSignature> { | ||
element?: CalciteInputText; | ||
|
||
constructor(owner: Owner, args: ArgsFor<DefaultSignature>) { | ||
super(owner, args); | ||
registerDestructor(this, this.cleanup); | ||
} | ||
|
||
@action | ||
onWHeel(e: WheelEvent) { | ||
if (!e.deltaY) { | ||
return; | ||
} | ||
|
||
const step = e.ctrlKey ? 10 : e.altKey ? 0.1 : 1; | ||
const factor = e.deltaY < 0 ? 1 : -1; | ||
const newValue = Number(parseFloat(this.element!.value) + step * factor).toFixed(2); | ||
|
||
this.element!.value = `${newValue}`; | ||
this.element!.dispatchEvent(new Event('calciteInputNumberChange')); | ||
|
||
e.preventDefault(); | ||
e.stopPropagation(); | ||
} | ||
|
||
@action | ||
cleanup() { | ||
this.element?.removeEventListener('wheel', this.onWHeel); | ||
} | ||
|
||
modify(element: CalciteInputText) { | ||
this.element = element; | ||
element.addEventListener('wheel', this.onWHeel); | ||
} | ||
} |