search: Refactor how close buttons are handled.

We refactor the following inputs to use a `placeholder-shown` CSS selector to
show/hide the close button, rather than custom JS logic:
- Filter topics field in the left sidebar
- Filter direct messages field under direct messages
- Stream message topic
This commit is contained in:
opmkumar
2024-09-24 04:34:10 +05:30
committed by GitHub
parent 5bde07c842
commit 1ddc1d2d12
7 changed files with 13 additions and 32 deletions

View File

@@ -374,13 +374,6 @@ export function start(raw_opts: ComposeActionsStartOpts): void {
drafts.set_compose_draft_id(opts.draft_id); drafts.set_compose_draft_id(opts.draft_id);
} }
const $clear_topic_button = $("#recipient_box_clear_topic_button");
if (is_clear_topic_button_triggered || opts.topic.length === 0) {
$clear_topic_button.hide();
} else {
$clear_topic_button.show();
}
// Show a warning if topic is resolved // Show a warning if topic is resolved
compose_validate.warn_if_topic_resolved(true); compose_validate.warn_if_topic_resolved(true);
// Show a warning if the user is in a search narrow when replying to a message // Show a warning if the user is in a search narrow when replying to a message

View File

@@ -512,21 +512,8 @@ export function initialize() {
$("#compose_recipient_box").on("click", "#recipient_box_clear_topic_button", () => { $("#compose_recipient_box").on("click", "#recipient_box_clear_topic_button", () => {
const $input = $("input#stream_message_recipient_topic"); const $input = $("input#stream_message_recipient_topic");
const $button = $("#recipient_box_clear_topic_button");
$input.val(""); $input.val("");
$input.trigger("focus"); $input.trigger("focus");
$button.hide();
});
$("#compose_recipient_box").on("input", "input#stream_message_recipient_topic", (e) => {
const $button = $("#recipient_box_clear_topic_button");
const value = $(e.target).val();
if (value.length === 0) {
$button.hide();
} else {
$button.show();
}
}); });
$("input#stream_message_recipient_topic").on("focus", () => { $("input#stream_message_recipient_topic").on("focus", () => {

View File

@@ -62,11 +62,6 @@ export function _build_direct_messages_list(): vdom.Tag<PMNode> {
} }
const dom_ast = pm_list_dom.pm_ul(pm_list_nodes); const dom_ast = pm_list_dom.pm_ul(pm_list_nodes);
if (search_term === "") {
$("#clear-direct-messages-search-button").hide();
} else {
$("#clear-direct-messages-search-button").show();
}
return dom_ast; return dom_ast;
} }

View File

@@ -407,7 +407,6 @@ export function zoom_in_topics(options: {stream_id: number | undefined}): void {
// Add search box for topics list. // Add search box for topics list.
$elt.children("div.bottom_left_row").append($(render_filter_topics())); $elt.children("div.bottom_left_row").append($(render_filter_topics()));
$("#filter-topic-input").trigger("focus"); $("#filter-topic-input").trigger("focus");
$("#clear_search_topic_button").hide();
} else { } else {
$elt.hide(); $elt.hide();
} }

View File

@@ -222,12 +222,6 @@ export class TopicListWidget {
vdom.update(replace_content, find, new_dom, this.prior_dom); vdom.update(replace_content, find, new_dom, this.prior_dom);
this.prior_dom = new_dom; this.prior_dom = new_dom;
if ($("#filter-topic-input").val() !== "") {
$("#clear_search_topic_button").show();
} else {
$("#clear_search_topic_button").hide();
}
} }
} }

View File

@@ -960,6 +960,10 @@ textarea.new_message_textarea {
} }
} }
#stream_message_recipient_topic:placeholder-shown
+ #recipient_box_clear_topic_button {
display: none;
}
/* This will reset the bootstrap margin-bottom: 10px value for the inputs */ /* This will reset the bootstrap margin-bottom: 10px value for the inputs */
& input { & input {
margin-bottom: 0; margin-bottom: 0;

View File

@@ -1000,6 +1000,10 @@ li.top_left_scheduled_messages {
grid-area: row-content; grid-area: row-content;
} }
#filter-topic-input:placeholder-shown + #clear_search_topic_button {
display: none;
}
.searching-for-more-topics img { .searching-for-more-topics img {
height: 16px; height: 16px;
grid-area: row-content; grid-area: row-content;
@@ -1439,6 +1443,11 @@ li.topic-list-item {
to make a generous clickable area. */ to make a generous clickable area. */
padding: 0; padding: 0;
} }
.direct-messages-list-filter:placeholder-shown
+ #clear-direct-messages-search-button {
display: none;
}
} }
/* Prepare an adjusted grid for the logged-out state, /* Prepare an adjusted grid for the logged-out state,