fixed tags automatically adding on enter press
This commit is contained in:
parent
fdcfb24e48
commit
1a4a674cf6
1 changed files with 19 additions and 16 deletions
|
@ -34,7 +34,7 @@ const StyledSearchContainer = styled.div`
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const StyledSearchControlContainer = styled.form`
|
const StyledSearchControlContainer = styled.div`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-left: 1rem;
|
margin-left: 1rem;
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ const StyledSearchBar = styled.input`
|
||||||
})};
|
})};
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// check if post date is withing the range
|
||||||
function isDateInRange(
|
function isDateInRange(
|
||||||
dateToCompare: string,
|
dateToCompare: string,
|
||||||
from: string,
|
from: string,
|
||||||
|
@ -135,7 +136,8 @@ function _Search() {
|
||||||
|
|
||||||
function doSearch() {
|
function doSearch() {
|
||||||
// remove focus from search bar to prevent accidental multiple search
|
// remove focus from search bar to prevent accidental multiple search
|
||||||
if (inputRef.current) inputRef.current.blur()
|
if (document.activeElement instanceof HTMLElement)
|
||||||
|
document.activeElement.blur()
|
||||||
|
|
||||||
_history.push({
|
_history.push({
|
||||||
pathname: "/search",
|
pathname: "/search",
|
||||||
|
@ -207,7 +209,6 @@ function _Search() {
|
||||||
moveRangeOnFirstSelection={false}
|
moveRangeOnFirstSelection={false}
|
||||||
retainEndDateOnFirstSelection={true}
|
retainEndDateOnFirstSelection={true}
|
||||||
ranges={dateRange}
|
ranges={dateRange}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
onChange={(item: OnDateRangeChangeProps) => {
|
onChange={(item: OnDateRangeChangeProps) => {
|
||||||
const historyToPush = {
|
const historyToPush = {
|
||||||
...(query.query && {
|
...(query.query && {
|
||||||
|
@ -247,7 +248,6 @@ function _Search() {
|
||||||
<StyledSearchControlContainer
|
<StyledSearchControlContainer
|
||||||
onSubmit={(event) => {
|
onSubmit={(event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if (searchInput) doSearch()
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<StyledSearchBar
|
<StyledSearchBar
|
||||||
|
@ -258,6 +258,9 @@ function _Search() {
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
setSearchInput(event.target.value)
|
setSearchInput(event.target.value)
|
||||||
}
|
}
|
||||||
|
onKeyPress={(e) =>
|
||||||
|
e.key === "Enter" && searchInput && doSearch()
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
@ -274,8 +277,7 @@ function _Search() {
|
||||||
<br />
|
<br />
|
||||||
date to: {query.to}
|
date to: {query.to}
|
||||||
<br />
|
<br />
|
||||||
<input
|
<button
|
||||||
type="submit"
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
_history.push({
|
_history.push({
|
||||||
pathname: "/search",
|
pathname: "/search",
|
||||||
|
@ -293,11 +295,11 @@ function _Search() {
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
value="Search test 1"
|
>
|
||||||
/>
|
Search test 1
|
||||||
|
</button>
|
||||||
|
|
|
|
||||||
<input
|
<button
|
||||||
type="submit"
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
_history.push({
|
_history.push({
|
||||||
pathname: "/search",
|
pathname: "/search",
|
||||||
|
@ -315,11 +317,11 @@ function _Search() {
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
value="Search test 2"
|
>
|
||||||
/>
|
Search test 2
|
||||||
|
</button>
|
||||||
<br />
|
<br />
|
||||||
<input
|
<button
|
||||||
type="submit"
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
_history.push({
|
_history.push({
|
||||||
pathname: "/search",
|
pathname: "/search",
|
||||||
|
@ -335,8 +337,9 @@ function _Search() {
|
||||||
|
|
||||||
setDateRange(defaultDateRange)
|
setDateRange(defaultDateRange)
|
||||||
}}
|
}}
|
||||||
value="clear date"
|
>
|
||||||
/>
|
Clear date
|
||||||
|
</button>
|
||||||
<br />
|
<br />
|
||||||
</StyledSearchControlContainer>
|
</StyledSearchControlContainer>
|
||||||
</StyledSearchContainer>
|
</StyledSearchContainer>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue