Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Add shake animation when topic name hits character limit
Tanaya Pawar28135f1736d6
diff --git a/web/src/compose_setup.ts b/web/src/compose_setup.tsindex c4dbe8d1568..737fb01d8c0 100644--- a/web/src/compose_setup.ts+++ b/web/src/compose_setup.ts@@ -35,6 +35,7 @@ import * as resize from "./resize.ts";import {unresolve_name} from "./resolved_topic.ts";import * as rows from "./rows.ts";import * as scheduled_messages from "./scheduled_messages.ts";+import {realm} from "./state_data.ts";import * as stream_data from "./stream_data.ts";import * as stream_settings_components from "./stream_settings_components.ts";import * as sub_store from "./sub_store.ts";@@ -686,11 +687,31 @@ export function initialize(): void {$compose_recipient.addClass("recently-focused");});+ function handle_topic_length_limit(): void {+ let topic = compose_state.topic();+ if (topic.length > realm.max_topic_length) {+ topic = topic.slice(0, realm.max_topic_length);+ compose_state.topic(topic);+ $("input#stream_message_recipient_topic").addClass("shake");+ }+ }++ $("input#stream_message_recipient_topic").on("animationend", function () {+ $(this).removeClass("shake");+ });+$("input#stream_message_recipient_topic").on("input", () => {+ handle_topic_length_limit();compose_recipient.update_placeholder_visibility();compose_recipient.update_compose_area_placeholder_text();});+ $("input#stream_message_recipient_topic").on("paste", () => {+ /* setTimeout is needed to allow the pasted content to be+ added to the input before checking the topic length limit,+ since the paste event fires before the input value is updated.*/+ setTimeout(handle_topic_length_limit, 0);+ });$("#private_message_recipient").on("focus", () => {// We don't want the `.recently-focused` class removed via// setTimeout from the "blur" event, if we're suddenlydiff --git a/web/styles/compose.css b/web/styles/compose.cssindex 494edfed2bc..cfbf2647456 100644--- a/web/styles/compose.css+++ b/web/styles/compose.css@@ -1146,6 +1146,13 @@ textarea.new_message_textarea {&.empty-topic-display::placeholder {color: var(--color-compose-recipient-box-text-color);}++ &.shake {+ animation: shake 0.3s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;+ transform: translate3d(0, 0, 0);+ backface-visibility: hidden;+ perspective: 1000px;+ }}#topic-not-mandatory-placeholder {diff --git a/web/templates/compose.hbs b/web/templates/compose.hbsindex 454f5b00ffe..26d133bf32a 100644--- a/web/templates/compose.hbs+++ b/web/templates/compose.hbs@@ -65,7 +65,7 @@<a role="button" class="conversation-arrow zulip-icon zulip-icon-chevron-right"></a></div><div id="compose-channel-recipient">- <input type="text" name="stream_message_recipient_topic" id="stream_message_recipient_topic" maxlength="{{ max_topic_length }}" value="" placeholder="{{t 'Topic' }}" autocomplete="off" tabindex="0" aria-label="{{t 'Topic' }}" />+ <input type="text" name="stream_message_recipient_topic" id="stream_message_recipient_topic" value="" placeholder="{{t 'Topic' }}" autocomplete="off" tabindex="0" aria-label="{{t 'Topic' }}" /><span id="topic-not-mandatory-placeholder" class="placeholder">{{> topic_not_mandatory_placeholder_text empty_string_topic_display_name=empty_string_topic_display_name}}</span>