Skip to content

Commit

Permalink
remove children autofocus & add Text Input focus
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreCrb authored and Your Name committed Feb 13, 2020
1 parent 0b93a46 commit dd7d3e6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
34 changes: 22 additions & 12 deletions src/components/inspector/controls/ChildrenControl.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
import React from "react";
import { Input } from "@chakra-ui/core";
import FormControl from "./FormControl";
import { useForm } from "../../../hooks/useForm";
import usePropsSelector from "../../../hooks/usePropsSelector";
import React, { useRef, useEffect } from 'react'
import { Input } from '@chakra-ui/core'
import FormControl from './FormControl'
import { useForm } from '../../../hooks/useForm'
import usePropsSelector from '../../../hooks/usePropsSelector'
import { useSelector } from 'react-redux'
import { getShowInputText } from '../../../core/selectors/app'

const ChildrenControl: React.FC = () => {
const { setValueFromEvent } = useForm();
const children = usePropsSelector("children");
const textInput = useRef<HTMLInputElement>(null)
const focusInput = useSelector(getShowInputText)
const { setValueFromEvent } = useForm()
const children = usePropsSelector('children')

useEffect(() => {
if (focusInput && textInput.current) {
textInput.current.focus()
}
}, [focusInput])

return (
<FormControl htmlFor="children" label="Text">
<Input
id="children"
name="children"
autoFocus
size="sm"
value={children || ""}
value={children || ''}
type="text"
onChange={setValueFromEvent}
ref={textInput}
/>
</FormControl>
);
};
)
}

export default ChildrenControl;
export default ChildrenControl
8 changes: 8 additions & 0 deletions src/core/models/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ type Overlay = undefined | { rect: DOMRect; id: string; type: ComponentType }
export type AppState = {
showLayout: boolean
showCode: boolean
focusInputText: boolean
overlay: undefined | Overlay
}

const app = createModel({
state: {
showLayout: true,
showCode: false,
focusInputText: false,
overlay: undefined,
} as AppState,
reducers: {
Expand All @@ -27,6 +29,12 @@ const app = createModel({
showCode: !state.showCode,
}
},
toggleInputText(state: AppState): AppState {
return {
...state,
focusInputText: !state.focusInputText,
}
},

setOverlay(state: AppState, overlay: Overlay | undefined): AppState {
return {
Expand Down
2 changes: 2 additions & 0 deletions src/core/selectors/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ import { RootState } from '../store'
export const getShowLayout = (state: RootState) => state.app.showLayout

export const getShowCode = (state: RootState) => state.app.showCode

export const getShowInputText = (state: RootState) => state.app.focusInputText
2 changes: 1 addition & 1 deletion src/hooks/useInteractive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const useInteractive = (
})

const ref = useRef<HTMLDivElement>(null)

let props = {
...component.props,
onMouseOver: (event: MouseEvent) => {
Expand All @@ -35,6 +34,7 @@ export const useInteractive = (
event.preventDefault()
event.stopPropagation()
dispatch.components.select(component.id)
dispatch.app.toggleInputText()
},
}

Expand Down

0 comments on commit dd7d3e6

Please sign in to comment.