Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6691f97

Browse files
committedNov 19, 2020
Improve text input focus tabbing, fix React key errors
1 parent 7180530 commit 6691f97

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed
 

‎components/SyntaxLookupWidget.js

+20-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components/SyntaxLookupWidget.res

+19-9
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module MdxComp = {
1010
`
1111
)
1212

13-
@bs.get
14-
external frontmatter: t => Js.Json.t = "frontmatter"
13+
/* @bs.get */
14+
/* external frontmatter: t => Js.Json.t = "frontmatter" */
1515
}
1616

1717
@module("misc_docs/syntax/decorator_module.mdx")
@@ -106,6 +106,9 @@ let getAnchor = path => {
106106

107107
module SearchBox = {
108108
@bs.send external focus: Dom.element => unit = "focus"
109+
@bs.send external blur: Dom.element => unit = "blur"
110+
111+
external toDomElement: Js.t<'a> => Dom.element = "%identity"
109112

110113
type state =
111114
| Active
@@ -129,8 +132,11 @@ module SearchBox = {
129132
let focusInput = () =>
130133
textInput.current->Js.Nullable.toOption->Belt.Option.forEach(el => el->focus)
131134

132-
let onAreaFocus = _evt => {
133-
if state === Inactive {
135+
let onAreaFocus = evt => {
136+
let el = ReactEvent.Focus.target(evt)
137+
let isDiv = Js.Null_undefined.isNullable(el["type"])
138+
139+
if isDiv && state === Inactive {
134140
focusInput()
135141
}
136142
}
@@ -175,6 +181,7 @@ module SearchBox = {
175181
<div
176182
tabIndex={-1}
177183
onFocus=onAreaFocus
184+
onBlur
178185
className={(
179186
state === Active ? "border-fire" : "border-fire-40"
180187
) ++ " flex items-center border rounded-lg py-4 px-5"}>
@@ -185,14 +192,13 @@ module SearchBox = {
185192
value
186193
ref={ReactDOM.Ref.domRef(textInput)}
187194
onFocus
188-
onBlur
189195
onKeyDown
190196
onChange={onChange}
191197
placeholder="Enter keywords or syntax..."
192198
className="text-16 outline-none ml-4 w-full"
193199
type_="text"
194200
/>
195-
<button className={value === "" ? "hidden" : "block"} onMouseDown=onMouseDownClear>
201+
<button onFocus className={value === "" ? "hidden" : "block"} onMouseDown=onMouseDownClear>
196202
<Icon.Close className="w-4 h-4 text-fire" />
197203
</button>
198204
</div>
@@ -218,7 +224,11 @@ module DetailBox = {
218224
React.string(first),
219225
<span className="text-fire"> {React.string(second)} </span>,
220226
React.string(third),
221-
]->React.array
227+
]
228+
->Belt.Array.mapWithIndex((i, el) => {
229+
<span key={Belt.Int.toString(i)}> el </span>
230+
})
231+
->React.array
222232
| more => Belt.Array.map(more, s => React.string(s))->React.array
223233
}
224234

@@ -347,8 +357,8 @@ let make = () => {
347357
</span>
348358
})
349359
let el =
350-
<div className="first:mt-0 mt-12">
351-
<Category key=title title> {React.array(children)} </Category>
360+
<div key=title className="first:mt-0 mt-12">
361+
<Category title> {React.array(children)} </Category>
352362
</div>
353363
Js.Array2.push(acc, el)->ignore
354364
acc

0 commit comments

Comments
 (0)
Please sign in to comment.