-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autofocus location search bar when switching tabs #6832
base: main
Are you sure you want to change the base?
Autofocus location search bar when switching tabs #6832
Conversation
93efc62
to
bdfff40
Compare
bdfff40
to
293ddab
Compare
293ddab
to
47f69da
Compare
Thank you for providing us with this work! It's definitely a nice addition! I have some concerns about the code though:
I have some suggestions for you if you would like to improve it yourself, or if you want me to do it I can submit another PR for this :) Here is how I would do it:
This would let the |
Thanks for the feedback @raksooo . I will try to rework the PR following your suggestions 👍 . |
47f69da
to
eb0169f
Compare
ae9dfbc
to
05590d2
Compare
@raksooo , changes applied following your suggestion ✌️ . |
1b1217e
to
3490e35
Compare
@@ -67,6 +67,7 @@ export const StyledClearIcon = styled(ImageView)({ | |||
}); | |||
|
|||
interface ISearchBarProps { | |||
searchInputRef?: React.Ref<HTMLInputElement>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your suggestion @raksooo , you showed me AutoSizingTextInputWithRef
as an example:
function AutoSizingTextInputWithRef(props: IInputProps, forwardedRef: React.Ref<HTMLInputElement>) { |
which consumes a forwardedRef
parameter, the ref
object does not come from its props
.
But here I was only able to pass it via a prop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To use the ref
-prop you will need to wrap the component in React.forwardRef
.
function SearchBar(props: ISearchBarProps, forwardedRef: React.Ref<HTMLInputElement>) { ... }
export default React.forwardRef(SearchBar);
Then you won't have to include it in props and you'll be able to use SearchBar
like this:
<SearchBar ref={searchInputRef} ... />
I think React.forwardRef
won't be needed in future versions of react, but for now we'll need to add it :)
3490e35
to
f7cb189
Compare
f7cb189
to
eb45c2e
Compare
Strangely tests are failing: https://github.com/mullvad/mullvadvpn-app/actions/runs/11314889729/job/31465392999#step:11:57 while I cannot reproduce locally: |
The failing test should be fixed in this PR: #6970 :) |
What this PR changes
This PR adds an autofocus to the search bar, of the
Selection location
view, when changing tabs.Why this is wanted
To contribute and implement the feature requested in #6554 .
(I know I was told the UI is going to be re-worked: #6554 (comment) , but I thought I could satisfy my curiosity by giving it a shot)
How it's implemented
By notifying when the location type has changed (using
useBoolean()
), while passing the information to the<SearchBar>
component.How to test the change
The autofocus of the search bar is currently not tested, even when it was initially added:
d5f216e
(#4163)Fixes #6554
This change is