mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
show a placeholder
This commit is contained in:
parent
7c055e8024
commit
521f239359
@ -5,55 +5,55 @@ import classnames from "classnames"
|
||||
import "./index.less"
|
||||
|
||||
const SearchButton = (props) => {
|
||||
const searchBoxRef = React.useRef(null)
|
||||
const searchBoxRef = React.useRef(null)
|
||||
|
||||
const [value, setValue] = React.useState()
|
||||
const [open, setOpen] = React.useState()
|
||||
const [value, setValue] = React.useState()
|
||||
const [open, setOpen] = React.useState()
|
||||
|
||||
const openSearchBox = (to) => {
|
||||
to = to ?? !open
|
||||
setOpen(to)
|
||||
const openSearchBox = (to) => {
|
||||
to = to ?? !open
|
||||
setOpen(to)
|
||||
|
||||
if (to) {
|
||||
searchBoxRef.current?.focus()
|
||||
}
|
||||
}
|
||||
if (to) {
|
||||
searchBoxRef.current?.focus()
|
||||
}
|
||||
}
|
||||
|
||||
const handleOnChange = (value) => {
|
||||
setValue(value)
|
||||
const handleOnChange = (value) => {
|
||||
setValue(value)
|
||||
|
||||
if (!value || value.length === 0 || value === "" || value === " ") {
|
||||
if (typeof props.onEmpty === "function") {
|
||||
props.onEmpty()
|
||||
}
|
||||
if (!value || value.length === 0 || value === "" || value === " ") {
|
||||
if (typeof props.onEmpty === "function") {
|
||||
props.onEmpty()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if (typeof props.onChange === "function") {
|
||||
props.onChange(value)
|
||||
}
|
||||
}
|
||||
if (typeof props.onChange === "function") {
|
||||
props.onChange(value)
|
||||
}
|
||||
}
|
||||
|
||||
return <div
|
||||
className="searchButton"
|
||||
onClick={() => openSearchBox(true)}
|
||||
>
|
||||
<Input
|
||||
ref={searchBoxRef}
|
||||
className={classnames("searchBox", { ["open"]: open })}
|
||||
onSearch={props.onSearch}
|
||||
onChange={handleOnChange}
|
||||
value={value}
|
||||
onFocus={() => openSearchBox(true)}
|
||||
onBlur={() => {
|
||||
if (value.length === 0) {
|
||||
openSearchBox(false)
|
||||
}
|
||||
}}
|
||||
disabled={props.disabled}
|
||||
/>
|
||||
</div>
|
||||
return (
|
||||
<div className="searchButton" onClick={() => openSearchBox(true)}>
|
||||
<Input
|
||||
ref={searchBoxRef}
|
||||
className={classnames("searchBox", { ["open"]: open })}
|
||||
placeholder="Type for search..."
|
||||
onSearch={props.onSearch}
|
||||
onChange={handleOnChange}
|
||||
value={value}
|
||||
onFocus={() => openSearchBox(true)}
|
||||
onBlur={() => {
|
||||
if (value.length === 0) {
|
||||
openSearchBox(false)
|
||||
}
|
||||
}}
|
||||
disabled={props.disabled}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default SearchButton
|
||||
export default SearchButton
|
||||
|
Loading…
x
Reference in New Issue
Block a user