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