backport of UI: focus navigate-input after page filter (#21862)
Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com>
This commit is contained in:
parent
e167798ea5
commit
72b46b87aa
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
ui: Fixed secrets, leases, and policies filter dropping focus after a single character
|
||||||
|
```
|
|
@ -2,17 +2,19 @@
|
||||||
<div class="field" data-test-nav-input>
|
<div class="field" data-test-nav-input>
|
||||||
<p class="control has-icons-left">
|
<p class="control has-icons-left">
|
||||||
{{! template-lint-disable no-down-event-binding }}
|
{{! template-lint-disable no-down-event-binding }}
|
||||||
<input
|
<Input
|
||||||
|
id={{this.inputId}}
|
||||||
class="filter input"
|
class="filter input"
|
||||||
value={{@filter}}
|
|
||||||
placeholder={{or @placeholder "Filter items"}}
|
placeholder={{or @placeholder "Filter items"}}
|
||||||
type="text"
|
@value={{@filter}}
|
||||||
|
@type="text"
|
||||||
data-test-component="navigate-input"
|
data-test-component="navigate-input"
|
||||||
{{on "input" this.handleInput}}
|
{{on "input" this.handleInput}}
|
||||||
{{on "keyup" this.handleKeyUp}}
|
{{on "keyup" this.handleKeyUp}}
|
||||||
{{on "keydown" this.handleKeyPress}}
|
{{on "keydown" this.handleKeyPress}}
|
||||||
{{on "focus" (fn this.setFilterFocused true)}}
|
{{on "focus" (fn this.setFilterFocused true)}}
|
||||||
{{on "blur" (fn this.setFilterFocused false)}}
|
{{on "blur" (fn this.setFilterFocused false)}}
|
||||||
|
{{did-insert this.maybeFocusInput}}
|
||||||
/>
|
/>
|
||||||
<Icon @name="search" class="search-icon has-text-grey-light" />
|
<Icon @name="search" class="search-icon has-text-grey-light" />
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -3,15 +3,17 @@
|
||||||
* SPDX-License-Identifier: MPL-2.0
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { debounce } from '@ember/runloop';
|
import { debounce, later } from '@ember/runloop';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
import Component from '@glimmer/component';
|
|
||||||
import { action } from '@ember/object';
|
import { action } from '@ember/object';
|
||||||
|
import { guidFor } from '@ember/object/internals';
|
||||||
|
import Component from '@glimmer/component';
|
||||||
|
|
||||||
// TODO MOVE THESE TO THE ADDON
|
// TODO MOVE THESE TO THE ADDON
|
||||||
import utils from 'vault/lib/key-utils';
|
import utils from 'vault/lib/key-utils';
|
||||||
import keys from 'vault/lib/keycodes';
|
import keys from 'vault/lib/keycodes';
|
||||||
import { encodePath } from 'vault/utils/path-encoding-helpers';
|
import { encodePath } from 'vault/utils/path-encoding-helpers';
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @module NavigateInput
|
* @module NavigateInput
|
||||||
|
@ -61,6 +63,7 @@ const routeFor = function (type, mode, urls) {
|
||||||
|
|
||||||
export default class NavigateInput extends Component {
|
export default class NavigateInput extends Component {
|
||||||
@service router;
|
@service router;
|
||||||
|
inputId = `nav-input-${guidFor(this)}`;
|
||||||
|
|
||||||
get mode() {
|
get mode() {
|
||||||
return this.args.mode || 'secrets';
|
return this.args.mode || 'secrets';
|
||||||
|
@ -129,7 +132,7 @@ export default class NavigateInput extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onTab(event) {
|
onTab(event) {
|
||||||
const firstPartialMatch = this.args.firstPartialMatch.id;
|
const firstPartialMatch = this.args.firstPartialMatch?.id;
|
||||||
if (!firstPartialMatch) {
|
if (!firstPartialMatch) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -190,14 +193,31 @@ export default class NavigateInput extends Component {
|
||||||
page: 1,
|
page: 1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
// component is not re-rendered on policy list so trigger autofocus here
|
||||||
|
this.maybeFocusInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
handleInput(filter) {
|
maybeFocusInput() {
|
||||||
if (this.args.filterDidChange) {
|
// if component is loaded and filter is already applied,
|
||||||
this.args.filterDidChange(filter.target.value);
|
// we assume the user just typed in a filter and the page reloaded
|
||||||
|
if (this.args.filter && !Ember.testing) {
|
||||||
|
later(
|
||||||
|
this,
|
||||||
|
function () {
|
||||||
|
document.getElementById(this.inputId).focus();
|
||||||
|
},
|
||||||
|
400
|
||||||
|
);
|
||||||
}
|
}
|
||||||
debounce(this, this.filterUpdated, filter.target.value, 200);
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
handleInput(evt) {
|
||||||
|
if (this.args.filterDidChange) {
|
||||||
|
this.args.filterDidChange(evt.target.value);
|
||||||
|
}
|
||||||
|
debounce(this, this.filterUpdated, evt.target.value, 400);
|
||||||
}
|
}
|
||||||
@action
|
@action
|
||||||
setFilterFocused(isFocused) {
|
setFilterFocused(isFocused) {
|
||||||
|
|
Loading…
Reference in New Issue