mirror of
https://github.com/zulip/zulip.git
synced 2025-11-17 12:21:58 +00:00
compose_box: Render limit indicator as template with zero-width space.
This commit is contained in:
@@ -5,6 +5,7 @@ import render_compose_banner from "../templates/compose_banner/compose_banner.hb
|
||||
import render_not_subscribed_warning from "../templates/compose_banner/not_subscribed_warning.hbs";
|
||||
import render_private_stream_warning from "../templates/compose_banner/private_stream_warning.hbs";
|
||||
import render_wildcard_warning from "../templates/compose_banner/wildcard_warning.hbs";
|
||||
import render_compose_limit_indicator from "../templates/compose_limit_indicator.hbs";
|
||||
|
||||
import * as channel from "./channel";
|
||||
import * as compose_banner from "./compose_banner";
|
||||
@@ -624,7 +625,12 @@ export function check_overflow_text() {
|
||||
if (text.length > max_length) {
|
||||
$indicator.addClass("over_limit");
|
||||
$("textarea#compose-textarea").addClass("over_limit");
|
||||
$indicator.text(text.length + "/" + max_length);
|
||||
$indicator.html(
|
||||
render_compose_limit_indicator({
|
||||
text_length: text.length,
|
||||
max_length,
|
||||
}),
|
||||
);
|
||||
compose_banner.show_error_message(
|
||||
$t(
|
||||
{
|
||||
@@ -640,8 +646,12 @@ export function check_overflow_text() {
|
||||
} else if (text.length > 0.9 * max_length) {
|
||||
$indicator.removeClass("over_limit");
|
||||
$("textarea#compose-textarea").removeClass("over_limit");
|
||||
$indicator.text(text.length + "/" + max_length);
|
||||
|
||||
$indicator.html(
|
||||
render_compose_limit_indicator({
|
||||
text_length: text.length,
|
||||
max_length,
|
||||
}),
|
||||
);
|
||||
$("#compose-send-button").prop("disabled", false);
|
||||
$(`#compose_banners .${CSS.escape(compose_banner.CLASSNAMES.message_too_long)}`).remove();
|
||||
} else {
|
||||
|
||||
2
web/templates/compose_limit_indicator.hbs
Normal file
2
web/templates/compose_limit_indicator.hbs
Normal file
@@ -0,0 +1,2 @@
|
||||
{{! Include a zero-width-space to allow breaks in narrow compose boxes. }}
|
||||
{{text_length}}​/{{max_length}}
|
||||
@@ -562,10 +562,14 @@ test_ui("test_check_overflow_text", ({mock_template}) => {
|
||||
});
|
||||
|
||||
// Indicator should show red colored text
|
||||
let limit_indicator_html;
|
||||
mock_template("compose_limit_indicator.hbs", true, (_data, html) => {
|
||||
limit_indicator_html = html;
|
||||
});
|
||||
$textarea.val("a".repeat(10000 + 1));
|
||||
compose_validate.check_overflow_text();
|
||||
assert.ok($indicator.hasClass("over_limit"));
|
||||
assert.equal($indicator.text(), "10001/10000");
|
||||
assert.equal(limit_indicator_html, "10001​/10000\n");
|
||||
assert.ok($textarea.hasClass("over_limit"));
|
||||
assert.ok(banner_rendered);
|
||||
assert.ok($send_button.prop("disabled"));
|
||||
@@ -575,7 +579,7 @@ test_ui("test_check_overflow_text", ({mock_template}) => {
|
||||
$textarea.val("a".repeat(9000 + 1));
|
||||
compose_validate.check_overflow_text();
|
||||
assert.ok(!$indicator.hasClass("over_limit"));
|
||||
assert.equal($indicator.text(), "9001/10000");
|
||||
assert.equal(limit_indicator_html, "9001​/10000\n");
|
||||
assert.ok(!$textarea.hasClass("over_limit"));
|
||||
assert.ok(!$send_button.prop("disabled"));
|
||||
assert.ok(!banner_rendered);
|
||||
|
||||
Reference in New Issue
Block a user