Skip to content

Commit 698e0b9

Browse files
make toolbar hotkeys work in fullscreen
1 parent 707a51d commit 698e0b9

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

src/components/viewer/ComponentViewer.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ export interface Props {
2929
}
3030

3131
class ComponentViewer extends Component<Props, ComponentViewerState> {
32-
private registries: Registries;
33-
private stateCreator: ComponentViewerStateCreator;
32+
private readonly registries: Registries;
33+
private readonly hotKeyBoundActions: HotKeyBoundActions;
3434

35-
private hotKeyBoundActions: HotKeyBoundActions;
35+
private stateCreator: ComponentViewerStateCreator;
3636

3737
constructor(props: Props) {
3838
super(props);
@@ -43,7 +43,9 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
4343
this.stateCreator = new ComponentViewerStateCreator(this.registries);
4444

4545
this.state = this.stateFromUrl();
46-
this.hotKeyBoundActions = {'Alt F': this.onFullScreenToggle};
46+
this.hotKeyBoundActions = {
47+
'Alt F': this.onFullScreenToggle,
48+
...this.dropDownKeyBoundActions()};
4749
}
4850

4951
render() {
@@ -169,6 +171,21 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
169171
this.unsubscribeFromUrlChanges();
170172
}
171173

174+
private dropDownKeyBoundActions() {
175+
const result: HotKeyBoundActions = {};
176+
177+
const {dropDown} = this.props;
178+
if (!dropDown) {
179+
return result;
180+
}
181+
182+
dropDown.items
183+
.filter(item => !!item.hotKey)
184+
.forEach(item => result[item.hotKey!] = () => this.selectToolbarItem(item.label));
185+
186+
return result;
187+
}
188+
172189
private subscribeToUrlChanges() {
173190
window.addEventListener('popstate', () => this.updateStateFromUrl());
174191
}

src/components/viewer/toolbar/ToolbarDropDown.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import * as React from 'react';
33
import { ToolbarDropDownItem } from './ToolbarDropDownItem';
44

55
import { ToolbarDropDownSelectionPlacement } from './ToolbarDropDownSelectionPlacement';
6-
import { GlobalHotKeysHandler } from '../../hotkeys/GlobalHotKeysHandler';
7-
8-
import { HotKeyBoundActions } from '../../hotkeys/HotKeyBoundActions';
9-
106
import { ToolbarDropDownSelectionItem } from './ToolbarDropDownSelectionItem';
117

128
import './ToolbarDropDown.css';
@@ -35,26 +31,13 @@ export class ToolbarDropDown extends React.Component<Props, State> {
3531

3632
return (
3733
<div className="rcv-toolbar-drop-down">
38-
<GlobalHotKeysHandler keyBoundActions={this.hotKeyBoundActions()}/>
39-
4034
<div className="rcv-toolbar-drop-down-label">{label}</div>
4135
{this.renderSelected()}
4236
{this.renderSelectionIfRequired()}
4337
</div>
4438
);
4539
}
4640

47-
private hotKeyBoundActions(): HotKeyBoundActions {
48-
const result: HotKeyBoundActions = {};
49-
50-
const {items} = this.props;
51-
items
52-
.filter(item => !!item.hotKey)
53-
.forEach(item => result[item.hotKey!] = () => this.onItemSelect(item.label));
54-
55-
return result;
56-
}
57-
5841
private saveSelectedLabelNode = (node: HTMLDivElement) => {
5942
this.selectedLabelNode = node;
6043
}

0 commit comments

Comments
 (0)