Skip to content

Commit f947d36

Browse files
Vertical toolbox fixes (#2017)
* Replace visibility property with display for hiding popover * Disable arrow right and left keys for popover * Revert "Replace visibility property with display for hiding popover" This reverts commit af521cf. * Hide popover via setting max-height to 0 to fix animation in safari * Remove redundant condition
1 parent c29d244 commit f947d36

File tree

4 files changed

+29
-37
lines changed

4 files changed

+29
-37
lines changed

src/components/flipper.ts

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ export interface FlipperOptions {
1818
items?: HTMLElement[];
1919

2020
/**
21-
* Defines arrows usage. By default Flipper leafs items also via RIGHT/LEFT.
22-
*
23-
* true by default
24-
*
25-
* Pass 'false' if you don't need this behaviour
26-
* (for example, Inline Toolbar should be closed by arrows,
27-
* because it means caret moving with selection clearing)
21+
* Optional callback for button click
2822
*/
29-
allowArrows?: boolean;
23+
activateCallback?: (item: HTMLElement) => void;
3024

3125
/**
32-
* Optional callback for button click
26+
* List of keys allowed for handling.
27+
* Can include codes of the following keys:
28+
* - Tab
29+
* - Enter
30+
* - Arrow up
31+
* - Arrow down
32+
* - Arrow right
33+
* - Arrow left
34+
* If not specified all keys are enabled
3335
*/
34-
activateCallback?: (item: HTMLElement) => void;
36+
allowedKeys?: number[];
3537
}
3638

3739
/**
@@ -53,11 +55,9 @@ export default class Flipper {
5355
private activated = false;
5456

5557
/**
56-
* Flag that allows arrows usage to flip items
57-
*
58-
* @type {boolean}
58+
* List codes of the keys allowed for handling
5959
*/
60-
private readonly allowArrows: boolean = true;
60+
private readonly allowedKeys: number[];
6161

6262
/**
6363
* Call back for button click/enter
@@ -68,9 +68,9 @@ export default class Flipper {
6868
* @param {FlipperOptions} options - different constructing settings
6969
*/
7070
constructor(options: FlipperOptions) {
71-
this.allowArrows = _.isBoolean(options.allowArrows) ? options.allowArrows : true;
7271
this.iterator = new DomIterator(options.items, options.focusedItemClass);
7372
this.activateCallback = options.activateCallback;
73+
this.allowedKeys = options.allowedKeys || Flipper.usedKeys;
7474
}
7575

7676
/**
@@ -206,23 +206,7 @@ export default class Flipper {
206206
* @returns {boolean}
207207
*/
208208
private isEventReadyForHandling(event: KeyboardEvent): boolean {
209-
const handlingKeyCodeList = [
210-
_.keyCodes.TAB,
211-
_.keyCodes.ENTER,
212-
];
213-
214-
const isCurrentItemIsFocusedInput = this.iterator.currentItem == document.activeElement;
215-
216-
if (this.allowArrows && !isCurrentItemIsFocusedInput) {
217-
handlingKeyCodeList.push(
218-
_.keyCodes.LEFT,
219-
_.keyCodes.RIGHT,
220-
_.keyCodes.UP,
221-
_.keyCodes.DOWN
222-
);
223-
}
224-
225-
return this.activated && handlingKeyCodeList.indexOf(event.keyCode) !== -1;
209+
return this.activated && this.allowedKeys.indexOf(event.keyCode) !== -1;
226210
}
227211

228212
/**

src/components/modules/toolbar/inline.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,10 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
698698
private enableFlipper(): void {
699699
this.flipper = new Flipper({
700700
focusedItemClass: this.CSS.focusedButton,
701-
allowArrows: false,
701+
allowedKeys: [
702+
_.keyCodes.ENTER,
703+
_.keyCodes.TAB,
704+
],
702705
});
703706
}
704707
}

src/components/utils/popover.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Listeners from './listeners';
33
import Flipper from '../flipper';
44
import SearchInput from './search-input';
55
import EventsDispatcher from './events';
6-
import { isMobile } from '../utils';
6+
import { isMobile, keyCodes } from '../utils';
77

88
/**
99
* Describe parameters for rendering the single item of Popover
@@ -347,6 +347,12 @@ export default class Popover extends EventsDispatcher<PopoverEvent> {
347347
this.flipper = new Flipper({
348348
items: tools,
349349
focusedItemClass: Popover.CSS.itemFocused,
350+
allowedKeys: [
351+
keyCodes.TAB,
352+
keyCodes.UP,
353+
keyCodes.DOWN,
354+
keyCodes.ENTER,
355+
],
350356
});
351357
}
352358
}

src/styles/popover.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
.ce-popover {
22
position: absolute;
33
opacity: 0;
4-
visibility: hidden;
54
will-change: opacity, transform;
65
display: flex;
76
flex-direction: column;
87
padding: 4px;
98
min-width: 200px;
10-
max-height: 284px;
119
overflow: hidden;
1210
box-sizing: border-box;
1311
flex-shrink: 0;
12+
max-height: 0;
1413

1514
@apply --overlay-pane;
1615

@@ -19,7 +18,7 @@
1918

2019
&--opened {
2120
opacity: 1;
22-
visibility: visible;
21+
max-height: 284px;
2322
animation: panelShowing 100ms ease;
2423

2524
@media (--mobile) {

0 commit comments

Comments
 (0)