Skip to content

Commit c0ee66b

Browse files
committed
fixes
1 parent afcb9bc commit c0ee66b

3 files changed

Lines changed: 70 additions & 3 deletions

File tree

packages/core-ui/js/gui_components/import-export-controls.js

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ImportExportControls {
2727
this.defaultOptionsPanelWidthPx = 272;
2828
this.minOptionsPanelWidthPx = 180;
2929
this.maxOptionsPanelWidthPx = 520;
30+
this.minPreviewPanelWidthPx = 220;
3031
this.currentOptionsPanelWidthPx = null;
3132
this._activeSplitDrag = null;
3233
}
@@ -327,7 +328,8 @@ class ImportExportControls {
327328
text_area.style.width = '100%';
328329
text_area.style.height = '100%';
329330

330-
this._setOptionsPanelWidth(optionsparent, this._getInitialOptionsPanelWidthPx());
331+
const initialWidth = this._clampOptionsPanelWidth(this._getInitialOptionsPanelWidthPx(), edit_area);
332+
this._setOptionsPanelWidth(optionsparent, initialWidth);
331333
optionsparent.style.height = '100%';
332334

333335
optionsparent.innerHTML = '';
@@ -494,19 +496,26 @@ class ImportExportControls {
494496

495497
splitter.style.display = 'block';
496498
textArea.style.flex = '1 1 auto';
499+
this._updateSplitterAriaValues(splitter, optionsParent, editArea);
497500

498501
if (splitter.dataset.splitterInitialised === 'true') {
499502
return;
500503
}
501504

502505
splitter.dataset.splitterInitialised = 'true';
503506
splitter.addEventListener('pointerdown', (event) => this._beginSplitterDrag(event, editArea, optionsParent));
507+
splitter.addEventListener('keydown', (event) =>
508+
this._handleSplitterKeyDown(event, optionsParent, editArea, splitter)
509+
);
504510
}
505511

506512
_beginSplitterDrag(event, editArea, optionsParent) {
507513
if (!event || event.button > 0) {
508514
return;
509515
}
516+
if (this._activeSplitDrag) {
517+
return;
518+
}
510519

511520
const pointerId = event.pointerId;
512521
const startX = event.clientX;
@@ -541,6 +550,10 @@ class ImportExportControls {
541550
const requestedWidth = dragState.startWidth + deltaX;
542551
const boundedWidth = this._clampOptionsPanelWidth(requestedWidth, dragState.editArea);
543552
this._setOptionsPanelWidth(dragState.optionsParent, boundedWidth);
553+
const splitter = document.querySelector('div.options-preview-splitter');
554+
if (splitter) {
555+
this._updateSplitterAriaValues(splitter, dragState.optionsParent, dragState.editArea);
556+
}
544557
}
545558

546559
_endSplitterDrag(event, onMove, onEnd) {
@@ -567,6 +580,37 @@ class ImportExportControls {
567580
this.currentOptionsPanelWidthPx = safeWidth;
568581
}
569582

583+
_handleSplitterKeyDown(event, optionsParent, editArea, splitter) {
584+
if (!event) {
585+
return;
586+
}
587+
588+
const step = event.shiftKey ? 24 : 12;
589+
let requestedWidth = this._readOptionsPanelWidthPx(optionsParent);
590+
let handled = true;
591+
592+
if (event.key === 'ArrowLeft') {
593+
requestedWidth -= step;
594+
} else if (event.key === 'ArrowRight') {
595+
requestedWidth += step;
596+
} else if (event.key === 'Home') {
597+
requestedWidth = this.minOptionsPanelWidthPx;
598+
} else if (event.key === 'End') {
599+
requestedWidth = this.maxOptionsPanelWidthPx;
600+
} else {
601+
handled = false;
602+
}
603+
604+
if (!handled) {
605+
return;
606+
}
607+
608+
event.preventDefault();
609+
const boundedWidth = this._clampOptionsPanelWidth(requestedWidth, editArea);
610+
this._setOptionsPanelWidth(optionsParent, boundedWidth);
611+
this._updateSplitterAriaValues(splitter, optionsParent, editArea);
612+
}
613+
570614
_readOptionsPanelWidthPx(optionsParent) {
571615
const parsed = Number.parseFloat(optionsParent?.style?.width || '');
572616
if (Number.isFinite(parsed)) {
@@ -585,10 +629,24 @@ class ImportExportControls {
585629
_clampOptionsPanelWidth(widthPx, editArea) {
586630
const editWidth = editArea?.getBoundingClientRect?.().width || 0;
587631
const maxByContainer =
588-
editWidth > 0 ? Math.max(this.minOptionsPanelWidthPx, editWidth - 220) : this.maxOptionsPanelWidthPx;
632+
editWidth > 0
633+
? Math.max(this.minOptionsPanelWidthPx, editWidth - this.minPreviewPanelWidthPx)
634+
: this.maxOptionsPanelWidthPx;
589635
const maxAllowed = Math.min(this.maxOptionsPanelWidthPx, maxByContainer);
590636
return Math.min(Math.max(widthPx, this.minOptionsPanelWidthPx), maxAllowed);
591637
}
638+
639+
_updateSplitterAriaValues(splitter, optionsParent, editArea) {
640+
if (!splitter) {
641+
return;
642+
}
643+
const min = this.minOptionsPanelWidthPx;
644+
const max = this._clampOptionsPanelWidth(this.maxOptionsPanelWidthPx, editArea);
645+
const now = this._clampOptionsPanelWidth(this._readOptionsPanelWidthPx(optionsParent), editArea);
646+
splitter.setAttribute('aria-valuemin', `${min}`);
647+
splitter.setAttribute('aria-valuemax', `${max}`);
648+
splitter.setAttribute('aria-valuenow', `${now}`);
649+
}
592650
}
593651

594652
export { ImportExportControls };

packages/core-ui/js/gui_components/tabbed-text-control.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ class TabbedTextControl {
5050
5151
<div class="edit-area">
5252
<div class="options-parent" style="display: none"></div>
53-
<div class="options-preview-splitter" style="display: none" role="separator" aria-orientation="vertical" aria-label="Resize options panel"></div>
53+
<div
54+
class="options-preview-splitter"
55+
style="display: none"
56+
role="separator"
57+
tabindex="0"
58+
aria-orientation="vertical"
59+
aria-label="Resize options panel"
60+
></div>
5461
<div id="markdown" style="height: 30%; width:100%;">
5562
<textarea class="textrepresentation" name="Markdown" id="markdownarea"></textarea>
5663
</div>

styles.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ button:disabled{
228228
flex: 0 0 8px;
229229
opacity: 0.7;
230230
transition: background-color 120ms ease, opacity 120ms ease;
231+
touch-action: none;
232+
-webkit-user-select: none;
231233
}
232234

233235
.options-preview-splitter:hover{

0 commit comments

Comments
 (0)