|
1 |
| -import { Component, Input, HostBinding, EventEmitter, Output } from '@angular/core'; |
| 1 | +import { Component, Input, HostBinding, EventEmitter, Output, HostListener } from '@angular/core'; |
2 | 2 | import { SplitterType } from '../splitter.component';
|
3 | 3 | import { IgxSplitterPaneComponent } from '../splitter-pane/splitter-pane.component';
|
4 | 4 | import { IDragMoveEventArgs, IDragStartEventArgs } from '../../directives/drag-drop/drag-drop.directive';
|
@@ -84,14 +84,74 @@ export class IgxSplitBarComponent {
|
84 | 84 | return this.type === SplitterType.Horizontal ? 'arrow_left' : 'arrow_drop_up';
|
85 | 85 | }
|
86 | 86 |
|
87 |
| - |
88 | 87 | /**
|
89 | 88 | * A temporary holder for the pointer coordinates.
|
90 | 89 | * @private
|
91 | 90 | * @memberof SplitBarComponent
|
92 | 91 | */
|
93 | 92 | private startPoint!: number;
|
94 | 93 |
|
| 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 | + |
95 | 155 | public onDragStart(event: IDragStartEventArgs) {
|
96 | 156 | if (this.resizeDisallowed) {
|
97 | 157 | event.cancel = true;
|
@@ -122,4 +182,55 @@ export class IgxSplitBarComponent {
|
122 | 182 | return !!relatedTabs.find(x => x.resizable === false);
|
123 | 183 | }
|
124 | 184 |
|
| 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 | + } |
125 | 236 | }
|
0 commit comments