interface: track suspended element when leap loads

This commit is contained in:
Tyler Brown Cifu Shuster 2020-08-16 21:12:31 -07:00
parent 54a7acbfc2
commit 494275b6ab
4 changed files with 15 additions and 3 deletions

View File

@ -3,7 +3,7 @@ import { StoreState } from '../../store/type';
import { Cage } from '../../types/cage'; import { Cage } from '../../types/cage';
import { LocalUpdate } from '../../types/local-update'; import { LocalUpdate } from '../../types/local-update';
type LocalState = Pick<StoreState, 'sidebarShown' | 'omniboxShown' | 'dark' | 'baseHash'>; type LocalState = Pick<StoreState, 'sidebarShown' | 'omniboxShown' | 'dark' | 'baseHash' | 'suspendedFocus'>;
export default class LocalReducer<S extends LocalState> { export default class LocalReducer<S extends LocalState> {
reduce(json: Cage, state: S) { reduce(json: Cage, state: S) {
@ -24,6 +24,13 @@ export default class LocalReducer<S extends LocalState> {
omniboxShown(obj: LocalUpdate, state: S) { omniboxShown(obj: LocalUpdate, state: S) {
if ('omniboxShown' in obj) { if ('omniboxShown' in obj) {
state.omniboxShown = !state.omniboxShown; state.omniboxShown = !state.omniboxShown;
if (state.suspendedFocus) {
state.suspendedFocus.focus();
state.suspendedFocus = null;
} else {
state.suspendedFocus = document.activeElement;
document.activeElement?.blur();
}
} }
} }

View File

@ -42,6 +42,7 @@ export default class GlobalStore extends BaseStore<StoreState> {
connection: 'connected', connection: 'connected',
sidebarShown: true, sidebarShown: true,
omniboxShown: false, omniboxShown: false,
suspendedFocus: null,
baseHash: null, baseHash: null,
invites: {}, invites: {},
associations: { associations: {

View File

@ -16,6 +16,7 @@ export interface StoreState {
// local state // local state
sidebarShown: boolean; sidebarShown: boolean;
omniboxShown: boolean; omniboxShown: boolean;
suspendedFocus: HTMLInputElement | null;
dark: boolean; dark: boolean;
connection: ConnectionStatus; connection: ConnectionStatus;
baseHash: string | null; baseHash: string | null;

View File

@ -80,8 +80,11 @@ render() {
{this.props.prompt} {this.props.prompt}
</span> </span>
<input <input
autoCorrect="false" autocorrect="off"
autoFocus={true} autocapitalize="off"
spellcheck="false"
tabindex="0"
wrap="off"
className="mono ml1 flex-auto dib w-100" className="mono ml1 flex-auto dib w-100"
id="dojo" id="dojo"
cursor={this.props.cursor} cursor={this.props.cursor}