Skip to content

Commit edeede4

Browse files
JesmoDeviOvergaard
authored andcommitted
add arrow key movement
1 parent a6f3c6c commit edeede4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/packages/core/components/split-panel/split-panel.element.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,24 @@ export class UmbSplitPanelElement extends LitElement {
222222
this.#connect();
223223
}
224224

225+
#onKeydown(event: KeyboardEvent) {
226+
if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
227+
const { width } = this.mainElement.getBoundingClientRect();
228+
const divider = this.dividerElement.getBoundingClientRect();
229+
230+
const dividerPos = divider.left - this.mainElement.getBoundingClientRect().left;
231+
const percentageFromWidth = (dividerPos / width) * 100;
232+
233+
const multiplier = event.shiftKey ? 10 : 1;
234+
const step = 1 * multiplier * (event.key === 'ArrowLeft' ? -1 : 1);
235+
236+
const newPercent = percentageFromWidth + step;
237+
const toPixels = (newPercent / 100) * this.mainElement.getBoundingClientRect().width;
238+
239+
this.#setPosition(toPixels);
240+
}
241+
}
242+
225243
render() {
226244
return html`
227245
<div id="main">
@@ -230,7 +248,7 @@ export class UmbSplitPanelElement extends LitElement {
230248
@slotchange=${this.#onSlotChanged}
231249
style="width: ${this._hasStartPanel ? '100%' : '0'}"></slot>
232250
<div id="divider">
233-
<div id="divider-touch-area" tabindex="0"></div>
251+
<div id="divider-touch-area" tabindex="0" @keydown=${this.#onKeydown}></div>
234252
</div>
235253
<slot name="end" @slotchange=${this.#onSlotChanged} style="width: ${this._hasEndPanel ? '100%' : '0'}"></slot>
236254
</div>

0 commit comments

Comments
 (0)