Skip to content

Commit f1e8d30

Browse files
Vasil MihalkovVasil Mihalkov
authored andcommitted
feat(splitter): Allow expand/collapse with keyboard #6639
1 parent 8c32bc7 commit f1e8d30

File tree

2 files changed

+84
-15
lines changed

2 files changed

+84
-15
lines changed

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

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,43 +107,66 @@ export class IgxSplitBarComponent {
107107
private sibling!: IgxSplitterPaneComponent;
108108

109109
/**
110-
* @hidden
111-
* @internal
112-
*/
110+
* @hidden
111+
* @internal
112+
*/
113113
@HostListener('keydown', ['$event'])
114114
keyEvent(event: KeyboardEvent) {
115115
const key = event.key.toLowerCase();
116+
const ctrl = event.ctrlKey;
116117
event.stopPropagation();
117-
if (this.pane.resizable && this.siblings[0].resizable) {
118118
switch (key) {
119119
case 'arrowup':
120120
if (this.type === 1) {
121-
event.preventDefault();
122-
this.moveUpOrLeft();
121+
if (ctrl) {
122+
this.pane.hidden ? this.onCollapsing(true) : this.onCollapsing(false);
123+
break;
124+
}
125+
if (this.pane.resizable && this.siblings[1].resizable) {
126+
event.preventDefault();
127+
this.moveUpOrLeft();
128+
}
123129
}
124130
break;
125131
case 'arrowdown':
126132
if (this.type === 1) {
127-
event.preventDefault();
128-
this.moveDownOrRight();
133+
if (ctrl) {
134+
this.siblings[1].hidden ? this.onCollapsing(false) : this.onCollapsing(true);
135+
break;
136+
}
137+
if (this.pane.resizable && this.siblings[1].resizable) {
138+
event.preventDefault();
139+
this.moveDownOrRight();
140+
}
129141
}
130142
break;
131143
case 'arrowleft':
132144
if (this.type === 0) {
133-
event.preventDefault();
134-
this.moveUpOrLeft();
145+
if (ctrl) {
146+
this.pane.hidden ? this.onCollapsing(true) : this.onCollapsing(false);
147+
break;
148+
}
149+
if (this.pane.resizable && this.siblings[1].resizable) {
150+
event.preventDefault();
151+
this.moveUpOrLeft();
152+
}
135153
}
136154
break;
137155
case 'arrowright':
138156
if (this.type === 0) {
139-
event.preventDefault();
140-
this.moveDownOrRight();
157+
if (ctrl) {
158+
this.siblings[1].hidden ? this.onCollapsing(false) : this.onCollapsing(true);
159+
break;
160+
}
161+
if (this.pane.resizable && this.siblings[1].resizable) {
162+
event.preventDefault();
163+
this.moveDownOrRight();
164+
}
141165
}
142166
break;
143167
default:
144168
break;
145169
}
146-
}
147170
}
148171

149172
public get nextButtonHidden() {
@@ -216,7 +239,7 @@ export class IgxSplitBarComponent {
216239
}
217240

218241
private panesInitialization() {
219-
this.sibling = this.siblings[0];
242+
this.sibling = this.siblings[1];
220243

221244
const paneRect = this.pane.element.getBoundingClientRect();
222245
this.initialPaneSize = this.type === SplitterType.Horizontal ? paneRect.width : paneRect.height;
@@ -230,7 +253,7 @@ export class IgxSplitBarComponent {
230253
this.sibling.size = this.type === SplitterType.Horizontal ? siblingRect.width : siblingRect.height;
231254
}
232255
}
233-
256+
234257
public onCollapsing(next: boolean) {
235258
const prevSibling = this.siblings[0];
236259
const nextSibling = this.siblings[1];

projects/igniteui-angular/src/lib/splitter/splitter.component.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,52 @@ describe('IgxSplitter', () => {
191191
expect(parseFloat(pane2.size)).toBeCloseTo(pane2_originalSize - 10, 0);
192192
});
193193

194+
fit('should allow expand/collapse with Ctrl + up/down arrow keys', () => {
195+
fixture.componentInstance.type = SplitterType.Vertical;
196+
fixture.detectChanges();
197+
const pane1 = splitter.panes.toArray()[0];
198+
const pane2 = splitter.panes.toArray()[1];
199+
expect(pane1.size).toBe('auto');
200+
expect(pane2.size).toBe('auto');
201+
const splitterBarComponent: DebugElement = fixture.debugElement.query(By.css(SPLITTERBAR_CLASS));
202+
splitterBarComponent.nativeElement.focus();
203+
UIInteractions.triggerEventHandlerKeyDown('ArrowUp', splitterBarComponent, false, false, true);
204+
fixture.detectChanges();
205+
expect(pane1.hidden).toBeTruthy();
206+
UIInteractions.triggerEventHandlerKeyDown('ArrowDown', splitterBarComponent, false, false, true);
207+
fixture.detectChanges();
208+
expect(pane1.hidden).toBeFalsy();
209+
UIInteractions.triggerEventHandlerKeyDown('ArrowDown', splitterBarComponent, false, false, true);
210+
fixture.detectChanges();
211+
expect(pane2.hidden).toBeTruthy();
212+
UIInteractions.triggerEventHandlerKeyDown('ArrowUp', splitterBarComponent, false, false, true);
213+
fixture.detectChanges();
214+
expect(pane2.hidden).toBeFalsy();
215+
});
216+
217+
fit('should allow expand/collapse with Ctrl + left/right arrow keys', () => {
218+
fixture.componentInstance.type = SplitterType.Horizontal;
219+
fixture.detectChanges();
220+
const pane1 = splitter.panes.toArray()[0];
221+
const pane2 = splitter.panes.toArray()[1];
222+
expect(pane1.size).toBe('auto');
223+
expect(pane2.size).toBe('auto');
224+
const splitterBarComponent: DebugElement = fixture.debugElement.query(By.css(SPLITTERBAR_CLASS));
225+
splitterBarComponent.nativeElement.focus();
226+
UIInteractions.triggerEventHandlerKeyDown('ArrowLeft', splitterBarComponent, false, false, true);
227+
fixture.detectChanges();
228+
expect(pane1.hidden).toBeTruthy();
229+
UIInteractions.triggerEventHandlerKeyDown('ArrowRight', splitterBarComponent, false, false, true);
230+
fixture.detectChanges();
231+
expect(pane1.hidden).toBeFalsy();
232+
UIInteractions.triggerEventHandlerKeyDown('ArrowRight', splitterBarComponent, false, false, true);
233+
fixture.detectChanges();
234+
expect(pane2.hidden).toBeTruthy();
235+
UIInteractions.triggerEventHandlerKeyDown('ArrowLeft', splitterBarComponent, false, false, true);
236+
fixture.detectChanges();
237+
expect(pane2.hidden).toBeFalsy();
238+
});
239+
194240
});
195241

196242
@Component({

0 commit comments

Comments
 (0)