Esc, enter key handling in search control

This commit is contained in:
Robin Davies
2024-10-12 20:51:45 -04:00
parent b9c3ad2367
commit 3c8b34cd38
2 changed files with 24 additions and 2 deletions
+8
View File
@@ -607,6 +607,11 @@ export const LoadPluginDialog =
this.hSearchTimeout = undefined; this.hSearchTimeout = undefined;
} }
handleApplyFilter()
{
this.handleSearchStringReady();
}
cancelSearchTimeout() cancelSearchTimeout()
{ {
if (this.hSearchTimeout) { if (this.hSearchTimeout) {
@@ -734,6 +739,9 @@ export const LoadPluginDialog =
onTextChanged={(text) => { onTextChanged={(text) => {
this.handleSearchStringChanged(text); this.handleSearchStringChanged(text);
}} }}
onApplyFilter={() => {
this.handleApplyFilter();
}}
onClearFilterClick={() => { onClearFilterClick={() => {
if (this.state.search_string !== "") { if (this.state.search_string !== "") {
this.requestScrollTo(); this.requestScrollTo();
+16 -2
View File
@@ -17,7 +17,7 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import React from 'react'; import React, { KeyboardEvent } from 'react';
import { Theme } from '@mui/material/styles'; import { Theme } from '@mui/material/styles';
import { WithStyles } from '@mui/styles'; import { WithStyles } from '@mui/styles';
import withStyles from '@mui/styles/withStyles'; import withStyles from '@mui/styles/withStyles';
@@ -39,6 +39,7 @@ interface SearchControlProps extends WithStyles<typeof styles> {
onTextChanged: (searchString: string) => void; onTextChanged: (searchString: string) => void;
onClick: () => void; onClick: () => void;
onClearFilterClick: () => void; onClearFilterClick: () => void;
onApplyFilter: () => void;
inputRef?: React.RefObject<HTMLInputElement>; inputRef?: React.RefObject<HTMLInputElement>;
showSearchIcon?: boolean showSearchIcon?: boolean
@@ -66,6 +67,17 @@ const SearchControl = withStyles(styles, { withTheme: true })(
} }
return this.defaultInputRef; return this.defaultInputRef;
} }
onKeyDown(ev: KeyboardEvent)
{
ev.stopPropagation(); // don't let the ENTER key propagate propagate the enclosing dialog Enter key handler.
if (ev.key === "Enter")
{
this.props.onApplyFilter();
} else if (ev.key === "Escape")
{
this.props.onClearFilterClick();
}
}
componentDidUpdate(oldProps: SearchControlProps) { componentDidUpdate(oldProps: SearchControlProps) {
if (oldProps.collapsed ?? false !== this.props.collapsed ?? false) { if (oldProps.collapsed ?? false !== this.props.collapsed ?? false) {
let inputRef = this.getInputRef(); let inputRef = this.getInputRef();
@@ -96,7 +108,9 @@ const SearchControl = withStyles(styles, { withTheme: true })(
) )
} }
<Input spellCheck={false} style={{ <Input spellCheck={false}
onKeyDown={(ev)=>{this.onKeyDown(ev);}}
style={{
flex: "1 1", visibility: (this.props.collapsed ?? false) ? "collapse" : "visible", marginRight: 12, height: 32, flex: "1 1", visibility: (this.props.collapsed ?? false) ? "collapse" : "visible", marginRight: 12, height: 32,
}} }}
inputRef={this.getInputRef()} inputRef={this.getInputRef()}