Skip to content

Commit 1fd16fb

Browse files
Vasil MihalkovVasil Mihalkov
Vasil Mihalkov
authored and
Vasil Mihalkov
committed
feat(splitter): Added arrow keys interactions #6639
1 parent 29de04a commit 1fd16fb

File tree

2 files changed

+114
-3
lines changed

2 files changed

+114
-3
lines changed

Diff for: projects/igniteui-angular/src/lib/splitter/splitter-bar/splitter-bar.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="igx-splitter__bar" [style.flex-direction]="direction" igxDrag [ghost]="false"
1+
<div tabindex="0" class="igx-splitter__bar" [style.flex-direction]="direction" igxDrag [ghost]="false"
22
(dragStart)='onDragStart($event)'
33
(dragMove)="onDragMove($event)">
44
<div class="igx-splitter-bar-expander">

Diff for: projects/igniteui-angular/src/lib/splitter/splitter-bar/splitter-bar.component.ts

+113-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, HostBinding, EventEmitter, Output } from '@angular/core';
1+
import { Component, Input, HostBinding, EventEmitter, Output, HostListener } from '@angular/core';
22
import { SplitterType } from '../splitter.component';
33
import { IgxSplitterPaneComponent } from '../splitter-pane/splitter-pane.component';
44
import { IDragMoveEventArgs, IDragStartEventArgs } from '../../directives/drag-drop/drag-drop.directive';
@@ -84,14 +84,74 @@ export class IgxSplitBarComponent {
8484
return this.type === SplitterType.Horizontal ? 'arrow_left' : 'arrow_drop_up';
8585
}
8686

87-
8887
/**
8988
* A temporary holder for the pointer coordinates.
9089
* @private
9190
* @memberof SplitBarComponent
9291
*/
9392
private startPoint!: number;
9493

94+
/**
95+
* A field that holds the initial size of the main `IgxSplitterPaneComponent` in each couple of panes devided by a gripper.
96+
* @private
97+
* @memberof SplitterComponent
98+
*/
99+
private initialPaneSize!: number;
100+
101+
/**
102+
* A field that holds the initial size of the sibling `IgxSplitterPaneComponent` in each couple of panes devided by a gripper.
103+
* @private
104+
* @memberof SplitterComponent
105+
*/
106+
private initialSiblingSize!: number;
107+
108+
/**
109+
* The sibling `IgxSplitterPaneComponent` in each couple of panes devided by a gripper.
110+
* @private
111+
* @memberof SplitterComponent
112+
*/
113+
private sibling!: IgxSplitterPaneComponent;
114+
115+
/**
116+
* @hidden
117+
* @internal
118+
*/
119+
@HostListener('keydown', ['$event'])
120+
keyEvent(event: KeyboardEvent) {
121+
const key = event.code.toLowerCase();
122+
event.stopPropagation();
123+
if (this.pane.resizable && this.siblings[0].resizable) {
124+
switch (key) {
125+
case 'arrowup':
126+
if (this.type === 1) {
127+
event.preventDefault();
128+
this.moveUpOrLeft();
129+
}
130+
break;
131+
case 'arrowdown':
132+
if (this.type === 1) {
133+
event.preventDefault();
134+
this.moveDownOrRight();
135+
}
136+
break;
137+
case 'arrowleft':
138+
if (this.type === 0) {
139+
event.preventDefault();
140+
this.moveUpOrLeft();
141+
}
142+
break;
143+
case 'arrowright':
144+
if (this.type === 0) {
145+
event.preventDefault();
146+
this.moveDownOrRight();
147+
}
148+
break;
149+
default:
150+
break;
151+
}
152+
}
153+
}
154+
95155
public onDragStart(event: IDragStartEventArgs) {
96156
if (this.resizeDisallowed) {
97157
event.cancel = true;
@@ -122,4 +182,55 @@ export class IgxSplitBarComponent {
122182
return !!relatedTabs.find(x => x.resizable === false);
123183
}
124184

185+
private moveUpOrLeft() {
186+
this.panesInitialization();
187+
188+
const min = parseInt(this.pane.minSize, 10) || 0;
189+
const max = parseInt(this.pane.maxSize, 10) || this.initialPaneSize + this.initialSiblingSize;
190+
const minSibling = parseInt(this.sibling.minSize, 10) || 0;
191+
const maxSibling = parseInt(this.sibling.maxSize, 10) || this.initialPaneSize + this.initialSiblingSize;
192+
193+
const paneSize = this.initialPaneSize - 10;
194+
const siblingSize = this.initialSiblingSize + 10;
195+
if (paneSize < min || paneSize > max || siblingSize < minSibling || siblingSize > maxSibling) {
196+
return;
197+
}
198+
199+
this.pane.size = paneSize + 'px';
200+
this.sibling.size = siblingSize + 'px';
201+
}
202+
203+
private moveDownOrRight() {
204+
this.panesInitialization();
205+
206+
const min = parseInt(this.pane.minSize, 10) || 0;
207+
const max = parseInt(this.pane.maxSize, 10) || this.initialPaneSize + this.initialSiblingSize;
208+
const minSibling = parseInt(this.sibling.minSize, 10) || 0;
209+
const maxSibling = parseInt(this.sibling.maxSize, 10) || this.initialPaneSize + this.initialSiblingSize;
210+
211+
const paneSize = this.initialPaneSize + 10;
212+
const siblingSize = this.initialSiblingSize - 10;
213+
if (paneSize < min || paneSize > max || siblingSize < minSibling || siblingSize > maxSibling) {
214+
return;
215+
}
216+
217+
this.pane.size = paneSize + 'px';
218+
this.sibling.size = siblingSize + 'px';
219+
}
220+
221+
private panesInitialization() {
222+
this.sibling = this.siblings[0];
223+
224+
const paneRect = this.pane.element.getBoundingClientRect();
225+
this.initialPaneSize = this.type === SplitterType.Horizontal ? paneRect.width : paneRect.height;
226+
if (this.pane.size === 'auto') {
227+
this.pane.size = this.type === SplitterType.Horizontal ? paneRect.width : paneRect.height;
228+
}
229+
230+
const siblingRect = this.sibling.element.getBoundingClientRect();
231+
this.initialSiblingSize = this.type === SplitterType.Horizontal ? siblingRect.width : siblingRect.height;
232+
if (this.sibling.size === 'auto') {
233+
this.sibling.size = this.type === SplitterType.Horizontal ? siblingRect.width : siblingRect.height;
234+
}
235+
}
125236
}

0 commit comments

Comments
 (0)