Skip to content

Commit 2e6130d

Browse files
committed
refactor(splitter): rename to nonResizable; port skip fn for key bindings (wip)
1 parent 65685bd commit 2e6130d

File tree

7 files changed

+51
-52
lines changed

7 files changed

+51
-52
lines changed

src/components/splitter/splitter-bar.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { partMap } from '../common/part-map.js';
1919
import { addResizeController } from '../resize-container/resize-controller.js';
2020
import type { SplitterOrientation } from '../types.js';
2121
import type IgcSplitterComponent from './splitter.js';
22-
import IgcSplitterPaneComponent from './splitter-pane.js';
22+
import type IgcSplitterPaneComponent from './splitter-pane.js';
2323
import { styles } from './themes/splitter-bar.base.css.js';
2424

2525
export interface IgcSplitterBarComponentEventMap {
@@ -84,7 +84,7 @@ export default class IgcSplitterBarComponent extends EventEmitterMixin<
8484

8585
private get _resizeDisallowed() {
8686
return !!this._siblingPanes.find(
87-
(x) => x && (x.resizable === false || x.collapsed === true)
87+
(x) => x && (x.nonResizable || x.collapsed)
8888
);
8989
}
9090

@@ -138,7 +138,7 @@ export default class IgcSplitterBarComponent extends EventEmitterMixin<
138138
cancel: () => {},
139139
});
140140

141-
addKeybindings(this)
141+
addKeybindings(this, { skip: this._shouldSkipResize })
142142
.set(arrowUp, this._handleResizePanes)
143143
.set(arrowDown, this._handleResizePanes)
144144
.set(arrowLeft, this._handleResizePanes)
@@ -157,28 +157,30 @@ export default class IgcSplitterBarComponent extends EventEmitterMixin<
157157
});
158158
}
159159

160-
private _handleResizePanes(event: KeyboardEvent) {
161-
if (this._resizeDisallowed) {
162-
return false;
160+
private _shouldSkipResize(_node: Element, event: KeyboardEvent): boolean {
161+
if (this._resizeDisallowed && !event.ctrlKey) {
162+
return true;
163163
}
164164
if (
165165
(event.key === arrowUp || event.key === arrowDown) &&
166-
this._orientation === 'horizontal'
166+
this._orientation === 'horizontal' &&
167+
!event.ctrlKey
167168
) {
168-
return false;
169+
return true;
169170
}
170171
if (
171172
(event.key === arrowLeft || event.key === arrowRight) &&
172-
this._orientation === 'vertical'
173+
this._orientation === 'vertical' &&
174+
!event.ctrlKey
173175
) {
174-
return false;
175-
}
176-
let delta = 0;
177-
if (event.key === arrowUp || event.key === arrowLeft) {
178-
delta = -10;
179-
} else {
180-
delta = 10;
176+
return true;
181177
}
178+
return false;
179+
}
180+
181+
private _handleResizePanes(event: KeyboardEvent) {
182+
const delta = event.key === arrowUp || event.key === arrowLeft ? -10 : 10;
183+
182184
this.emitEvent('igcMovingStart', { detail: this._siblingPanes[0]! });
183185
this.emitEvent('igcMoving', { detail: delta });
184186
this.emitEvent('igcMovingEnd', { detail: delta });
@@ -214,10 +216,8 @@ export default class IgcSplitterBarComponent extends EventEmitterMixin<
214216
Object.assign(this._internalStyles, { '--cursor': this._cursor });
215217
this.requestUpdate();
216218
},
217-
filter: [IgcSplitterPaneComponent.tagName],
218219
config: {
219-
attributeFilter: ['collapsed', 'resizable'],
220-
subtree: true,
220+
attributeFilter: ['collapsed', 'non-resizable'],
221221
},
222222
});
223223
}

src/components/splitter/splitter-pane.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ export default class IgcSplitterPaneComponent extends EventEmitterMixin<
124124
* Defines if the pane is resizable or not.
125125
* @attr
126126
*/
127-
@property({ type: Boolean, reflect: true })
128-
public resizable = true;
127+
@property({ type: Boolean, reflect: true, attribute: 'non-resizable' })
128+
public nonResizable = false;
129129

130130
/**
131131
* Collapsed state of the pane.

src/components/splitter/splitter.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ describe('Splitter', () => {
129129
const style = getComputedStyle(firstBar);
130130
expect(style.cursor).to.equal('col-resize');
131131

132-
firstPane.resizable = false;
132+
firstPane.nonResizable = true;
133133
await elementUpdated(splitter);
134134
await nextFrame();
135135

136136
expect(style.cursor).to.equal('default');
137137

138-
firstPane.resizable = true;
138+
firstPane.nonResizable = false;
139139
secondPane.collapsed = true;
140140
await elementUpdated(splitter);
141141
await nextFrame();
@@ -249,8 +249,8 @@ describe('Splitter', () => {
249249

250250
expect(splitter.panes[0].size).to.equal('30%');
251251
expect(splitter.panes[1].size).to.equal('70%');
252-
expect(style1.flex).to.equal('1 1 30%');
253-
expect(style2.flex).to.equal('1 1 70%');
252+
expect(style1.flex).to.equal('0 1 30%');
253+
expect(style2.flex).to.equal('0 1 70%');
254254

255255
expect(pane1.minSize).to.equal('20%');
256256
expect(pane1.maxSize).to.equal('80%');
@@ -323,7 +323,7 @@ describe('Splitter', () => {
323323
expect(pane.collapsed).to.be.false;
324324
});
325325

326-
it('should toggle the previous pane when the bar expander-end is clicked', async () => {
326+
it('should toggle the next pane when the bar expander-end is clicked', async () => {
327327
const bars = getSplitterBars(splitter);
328328
const firstBar = bars[0];
329329
const firstPane = splitter.panes[0];
@@ -340,10 +340,10 @@ describe('Splitter', () => {
340340
await elementUpdated(splitter);
341341
await nextFrame();
342342

343-
expect(firstPane.collapsed).to.be.true;
344-
expect(secondPane.collapsed).to.be.false;
345-
expect(expanderStart.hidden).to.be.true;
346-
expect(expanderEnd.hidden).to.be.false;
343+
expect(firstPane.collapsed).to.be.false;
344+
expect(secondPane.collapsed).to.be.true;
345+
expect(expanderStart.hidden).to.be.false;
346+
expect(expanderEnd.hidden).to.be.true;
347347

348348
expanderEnd.dispatchEvent(
349349
new PointerEvent('pointerdown', { bubbles: true })
@@ -357,7 +357,7 @@ describe('Splitter', () => {
357357
expect(expanderEnd.hidden).to.be.false;
358358
});
359359

360-
it('should toggle the next pane when the bar expander-start is clicked', async () => {
360+
it('should toggle the previous pane when the bar expander-start is clicked', async () => {
361361
const bars = getSplitterBars(splitter);
362362
const firstBar = bars[0];
363363
const firstPane = splitter.panes[0];
@@ -374,10 +374,10 @@ describe('Splitter', () => {
374374
await elementUpdated(splitter);
375375
await nextFrame();
376376

377-
expect(secondPane.collapsed).to.be.true;
378-
expect(firstPane.collapsed).to.be.false;
379-
expect(expanderStart.hidden).to.be.false;
380-
expect(expanderEnd.hidden).to.be.true;
377+
expect(firstPane.collapsed).to.be.true;
378+
expect(secondPane.collapsed).to.be.false;
379+
expect(expanderStart.hidden).to.be.true;
380+
expect(expanderEnd.hidden).to.be.false;
381381

382382
expanderStart.dispatchEvent(
383383
new PointerEvent('pointerdown', { bubbles: true })

src/components/splitter/themes/splitter-bar.base.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
:host {
44
--bar-size: 5px;
5+
56
display: flex;
67
background-color: var(--ig-gray-200);
78

src/components/splitter/themes/splitter-pane.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
height: 100%;
1313
}
1414

15-
1615
:host([collapsed]) [part='base'] {
1716
display: none;
1817
}

src/components/splitter/themes/splitter.base.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@
3232
[part='base'] {
3333
flex-direction: column;
3434
}
35-
3635
}

stories/splitter.stories.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ type SplitterStoryArgs = IgcSplitterComponent & {
1414
pane1MinSize?: string;
1515
pane1MaxSize?: string;
1616
pane1Collapsed?: boolean;
17-
pane1Resizable?: boolean;
17+
pane1NonResizable?: boolean;
1818

1919
/* Pane 2 properties */
2020
pane2Size?: string;
2121
pane2MinSize?: string;
2222
pane2MaxSize?: string;
2323
pane2Collapsed?: boolean;
24-
pane2Resizable?: boolean;
24+
pane2NonResizable?: boolean;
2525

2626
/* Pane 3 properties */
2727
pane3Size?: string;
2828
pane3MinSize?: string;
2929
pane3MaxSize?: string;
3030
pane3Collapsed?: boolean;
31-
pane3Resizable?: boolean;
31+
pane3NonResizable?: boolean;
3232
};
3333

3434
const metadata: Meta<SplitterStoryArgs> = {
@@ -69,7 +69,7 @@ const metadata: Meta<SplitterStoryArgs> = {
6969
description: 'Collapsed state of the first pane',
7070
table: { category: 'Pane 1' },
7171
},
72-
pane1Resizable: {
72+
pane1NonResizable: {
7373
control: 'boolean',
7474
description: 'Whether the first pane is resizable',
7575
table: { category: 'Pane 1' },
@@ -94,7 +94,7 @@ const metadata: Meta<SplitterStoryArgs> = {
9494
description: 'Collapsed state of the second pane',
9595
table: { category: 'Pane 2' },
9696
},
97-
pane2Resizable: {
97+
pane2NonResizable: {
9898
control: 'boolean',
9999
description: 'Whether the second pane is resizable',
100100
table: { category: 'Pane 2' },
@@ -119,7 +119,7 @@ const metadata: Meta<SplitterStoryArgs> = {
119119
description: 'Collapsed state of the third pane',
120120
table: { category: 'Pane 3' },
121121
},
122-
pane3Resizable: {
122+
pane3NonResizable: {
123123
control: 'boolean',
124124
description: 'Whether the third pane is resizable',
125125
table: { category: 'Pane 3' },
@@ -129,13 +129,13 @@ const metadata: Meta<SplitterStoryArgs> = {
129129
orientation: 'horizontal',
130130
nonCollapsible: false,
131131
pane1Size: 'auto',
132-
pane1Resizable: true,
132+
pane1NonResizable: false,
133133
pane1Collapsed: false,
134134
pane2Size: 'auto',
135-
pane2Resizable: true,
135+
pane2NonResizable: false,
136136
pane2Collapsed: false,
137137
pane3Size: 'auto',
138-
pane3Resizable: true,
138+
pane3NonResizable: false,
139139
pane3Collapsed: false,
140140
},
141141
};
@@ -165,17 +165,17 @@ export const Default: Story = {
165165
pane1MinSize,
166166
pane1MaxSize,
167167
pane1Collapsed,
168-
pane1Resizable,
168+
pane1NonResizable,
169169
pane2Size,
170170
pane2MinSize,
171171
pane2MaxSize,
172172
pane2Collapsed,
173-
pane2Resizable,
173+
pane2NonResizable,
174174
pane3Size,
175175
pane3MinSize,
176176
pane3MaxSize,
177177
pane3Collapsed,
178-
pane3Resizable,
178+
pane3NonResizable,
179179
}) => html`
180180
<style>
181181
.pane-content {
@@ -197,7 +197,7 @@ export const Default: Story = {
197197
.minSize=${pane1MinSize}
198198
.maxSize=${pane1MaxSize}
199199
?collapsed=${pane1Collapsed}
200-
?resizable=${pane1Resizable}
200+
?non-resizable=${pane1NonResizable}
201201
>
202202
<div class="pane-content">Pane 1</div>
203203
</igc-splitter-pane>
@@ -206,7 +206,7 @@ export const Default: Story = {
206206
.minSize=${pane2MinSize}
207207
.maxSize=${pane2MaxSize}
208208
?collapsed=${pane2Collapsed}
209-
?resizable=${pane2Resizable}
209+
?non-resizable=${pane2NonResizable}
210210
>
211211
<div class="pane-content">Pane 2</div>
212212
</igc-splitter-pane>
@@ -215,7 +215,7 @@ export const Default: Story = {
215215
.minSize=${pane3MinSize}
216216
.maxSize=${pane3MaxSize}
217217
?collapsed=${pane3Collapsed}
218-
?resizable=${pane3Resizable}
218+
?non-resizable=${pane3NonResizable}
219219
>
220220
<div class="pane-content">Pane 3</div>
221221
</igc-splitter-pane>

0 commit comments

Comments
 (0)