FIX: correctly filters input with pre-filled value (#20154)

Before this fix we would fill the input but that wouldn't trigger the actual filtering.
This commit is contained in:
Joffrey JAFFEUX 2023-02-02 23:49:36 +01:00 committed by GitHub
parent e66fa8c48b
commit 24f026c895
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 9 deletions

View File

@ -14,11 +14,14 @@
<DcFilterInput
@class="chat-emoji-picker__filter"
@value={{this.chatEmojiPickerManager.initialFilter}}
@filterAction={{this.didInputFilter}}
@filterAction={{action this.didInputFilter value="target.value"}}
@icons={{hash left="search"}}
placeholder={{i18n "chat.emoji_picker.search_placeholder"}}
autofocus={{true}}
{{did-insert this.focusFilter}}
{{did-insert
(fn this.didInputFilter this.chatEmojiPickerManager.initialFilter)
}}
>
<div
class="chat-emoji-picker__fitzpatrick-scale"

View File

@ -195,18 +195,13 @@ export default class ChatEmojiPicker extends Component {
}
@action
didInputFilter(event) {
if (!event.target.value.length) {
didInputFilter(value) {
if (!value?.length) {
this.filteredEmojis = null;
return;
}
discourseDebounce(
this,
this.debouncedDidInputFilter,
event.target.value,
INPUT_DELAY
);
discourseDebounce(this, this.debouncedDidInputFilter, value, INPUT_DELAY);
}
@action

View File

@ -108,6 +108,16 @@ RSpec.describe "Chat composer", type: :system, js: true do
expect(find(".chat-emoji-picker .dc-filter-input").value).to eq("gri")
end
it "filters with the prefilled input" do
chat.visit_channel(channel_1)
find(".chat-composer-input").fill_in(with: ":fr")
click_link(I18n.t("js.composer.more_emoji"))
expect(page).to have_selector(".chat-emoji-picker [data-emoji='fr']")
expect(page).to have_no_selector(".chat-emoji-picker [data-emoji='grinning']")
end
end
context "when typing on keyboard" do