get focus on clear field
This commit is contained in:
@@ -21,6 +21,7 @@ class BangSearchScreen extends HookConsumerWidget {
|
||||
final resultsAsync = ref.watch(bangSearchProvider);
|
||||
final incognitoEnabled = ref.watch(incognitoModeEnabledProvider);
|
||||
|
||||
final focusNode = useFocusNode();
|
||||
final textEditingController = useTextEditingController(
|
||||
text: initialSearchText,
|
||||
);
|
||||
@@ -37,6 +38,7 @@ class BangSearchScreen extends HookConsumerWidget {
|
||||
appBar: AppBar(
|
||||
title: TextField(
|
||||
enableIMEPersonalizedLearning: !incognitoEnabled,
|
||||
focusNode: focusNode,
|
||||
controller: textEditingController,
|
||||
autofocus: true,
|
||||
autocorrect: false,
|
||||
@@ -49,6 +51,7 @@ class BangSearchScreen extends HookConsumerWidget {
|
||||
context.pop();
|
||||
} else {
|
||||
textEditingController.clear();
|
||||
focusNode.requestFocus();
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.clear),
|
||||
|
||||
@@ -107,6 +107,7 @@ class _TabSheetHeader extends HookConsumerWidget {
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
searchTextController.clear();
|
||||
searchTextFocus.requestFocus();
|
||||
searchMode.value = false;
|
||||
},
|
||||
icon: const Icon(Icons.clear),
|
||||
|
||||
+3
@@ -16,6 +16,7 @@ class FindInPageWidget extends HookConsumerWidget {
|
||||
selectedTabStateProvider.select((state) => state?.findResultState),
|
||||
);
|
||||
|
||||
final focusNode = useFocusNode();
|
||||
final textController = useTextEditingController(
|
||||
text: searchResult?.lastSearchText ?? findInPageState.lastSearchText,
|
||||
keys: [searchResult?.lastSearchText, findInPageState.lastSearchText],
|
||||
@@ -31,6 +32,7 @@ class FindInPageWidget extends HookConsumerWidget {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
focusNode: focusNode,
|
||||
controller: textController,
|
||||
autofocus: true,
|
||||
autocorrect: false,
|
||||
@@ -81,6 +83,7 @@ class FindInPageWidget extends HookConsumerWidget {
|
||||
onPressed: () async {
|
||||
await ref.read(findInPageControllerProvider.notifier).hide();
|
||||
textController.clear();
|
||||
focusNode.requestFocus();
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
@@ -42,6 +42,8 @@ class SearchField extends HookConsumerWidget {
|
||||
() => textEditingController.text.isNotEmpty,
|
||||
);
|
||||
|
||||
final safeFocusNode = focusNode ?? useFocusNode();
|
||||
|
||||
final suggestion = useState<String?>(null);
|
||||
final lastText = useRef<String>(textEditingController.text);
|
||||
|
||||
@@ -71,7 +73,7 @@ class SearchField extends HookConsumerWidget {
|
||||
controller: textEditingController,
|
||||
suggestion: suggestion.value,
|
||||
enableIMEPersonalizedLearning: !incognitoEnabled,
|
||||
focusNode: focusNode,
|
||||
focusNode: safeFocusNode,
|
||||
autofocus: autofocus,
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
@@ -101,12 +103,9 @@ class SearchField extends HookConsumerWidget {
|
||||
},
|
||||
),
|
||||
),
|
||||
onTapOutside:
|
||||
(focusNode != null)
|
||||
? (event) {
|
||||
focusNode!.unfocus();
|
||||
}
|
||||
: null,
|
||||
onTapOutside: (event) {
|
||||
safeFocusNode.unfocus();
|
||||
},
|
||||
onSubmitted: onSubmitted,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class FeedArticleListScreen extends HookConsumerWidget {
|
||||
).select((value) => value.valueOrNull?.title.whenNotEmpty),
|
||||
);
|
||||
|
||||
final focusNode = useFocusNode();
|
||||
final searchTextController = useTextEditingController();
|
||||
|
||||
final hasText = useListenableSelector(
|
||||
@@ -65,6 +66,7 @@ class FeedArticleListScreen extends HookConsumerWidget {
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
focusNode: focusNode,
|
||||
controller: searchTextController,
|
||||
decoration: InputDecoration(
|
||||
label: const Text('Search'),
|
||||
@@ -73,6 +75,7 @@ class FeedArticleListScreen extends HookConsumerWidget {
|
||||
? IconButton(
|
||||
onPressed: () {
|
||||
searchTextController.clear();
|
||||
focusNode.requestFocus();
|
||||
},
|
||||
icon: const Icon(Icons.clear),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user