Skip to content

Commit c7c6f6a

Browse files
authored
fix: move searchbar to a real search type input (#1966)
<!-- Hello 👋 Thank you for submitting a pull request. To help us merge your PR, make sure to follow the instructions below: - Create or update the tests - Create or update the documentation at https://github.com/strapi/documentation - Refer to the issue you are closing in the PR description: Fix #issue - Specify if the PR is ready to be merged or work in progress (by opening a draft PR) Please ensure you read the Contributing Guide: https://github.com/strapi/strapi/blob/master/CONTRIBUTING.md --> ### What does it do? Actual Searchbar doesn't render a real search type input ### Why is it needed? Describe the issue you are solving. ### How to test it? Provide information about the environment and the path to verify the behaviour. ### Related issue(s)/PR(s) Let us know if this is related to any issue/pull request
2 parents 3427c70 + 5c5512c commit c7c6f6a

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

.changeset/blue-mirrors-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@strapi/design-system': minor
3+
---
4+
5+
fix: move searchbar to real search input type

packages/design-system/src/components/Searchbar/Searchbar.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const SearchIcon = styled(Search)`
2525

2626
const SearchbarWrapper = styled.div`
2727
border-radius: ${({ theme }) => theme.borderRadius};
28-
border: 1px solid ${({ theme }) => theme.colors.neutral150}
28+
border: 1px solid ${({ theme }) => theme.colors.neutral150};
2929
3030
&:focus-within {
3131
${SearchIcon} {
@@ -35,25 +35,44 @@ const SearchbarWrapper = styled.div`
3535
`;
3636

3737
const SearchbarInput = styled(Field.Input)`
38-
border: 1px solid ${({ theme }) => theme.colors.neutral150}
38+
border: 1px solid ${({ theme }) => theme.colors.neutral150};
3939
height: 16px;
4040
padding: 0 0 0 8px;
4141
color: ${({ theme }) => theme.colors.neutral800};
42-
42+
4343
&:hover {
4444
button {
4545
cursor: pointer;
4646
}
4747
}
4848
4949
${inputFocusStyle()}
50+
51+
> input::-ms-clear {
52+
display: none;
53+
width: 0;
54+
height: 0;
55+
}
56+
57+
> input::-ms-reveal {
58+
display: none;
59+
width: 0;
60+
height: 0;
61+
}
62+
63+
> input::-webkit-search-decoration,
64+
> input::-webkit-search-cancel-button,
65+
> input::-webkit-search-results-button,
66+
> input::-webkit-search-results-decoration {
67+
display: none;
68+
}
5069
`;
5170

5271
export interface SearchbarProps extends Field.InputProps {
5372
children: React.ReactNode;
5473
name: string;
5574
value?: string;
56-
onClear: React.MouseEventHandler<any>;
75+
onClear: React.MouseEventHandler<HTMLButtonElement>;
5776
clearLabel: string;
5877
}
5978

@@ -78,9 +97,16 @@ export const Searchbar = React.forwardRef<HTMLInputElement, SearchbarProps>(
7897

7998
<SearchbarInput
8099
size="S"
100+
type="search"
81101
ref={actualRef}
82102
value={value}
83103
startAction={<SearchIcon aria-hidden />}
104+
onKeyDown={(e) => {
105+
e.stopPropagation();
106+
if (e.key === 'Escape' && isCompleting) {
107+
handleClear(e);
108+
}
109+
}}
84110
endAction={
85111
isCompleting ? (
86112
<IconButton

0 commit comments

Comments
 (0)