Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

stream_create: Add shake animation when channel name hits character limit

Tanaya Pawar8d59cc965071
diff --git a/web/src/stream_create.ts b/web/src/stream_create.ts
index ef6b1e25935..9bdc976dfae 100644
--- a/web/src/stream_create.ts
+++ b/web/src/stream_create.ts
@@ -645,11 +645,27 @@ export function set_up_handlers(): void {
}
});
+ function handle_channel_name_length_limit(): void {
+ const $channel_input = $<HTMLInputElement>("input#create_stream_name");
+ let channel_name = $channel_input.val()!.trim();
+ if (channel_name.length > realm.max_stream_name_length) {
+ channel_name = channel_name.slice(0, realm.max_stream_name_length);
+ $channel_input.val(channel_name);
+ $channel_input.addClass("shake");
+ }
+ stream_name_error.pre_validate(channel_name);
+ }
+ $("input#create_stream_name").on("animationend", function () {
+ $(this).removeClass("shake");
+ });
$container.on("input", "#create_stream_name", () => {
- const stream_name = $<HTMLInputElement>("input#create_stream_name").val()!.trim();
-
- // This is an inexpensive check.
- stream_name_error.pre_validate(stream_name);
+ handle_channel_name_length_limit();
+ });
+ $container.on("paste", "#create_stream_name", () => {
+ /* setTimeout is needed to allow the pasted content to be
+ added to the input before checking the channel name length limit,
+ since the paste event fires before the input value is updated. */
+ setTimeout(handle_channel_name_length_limit, 0);
});
// Do not allow the user to enter newline characters while typing out the
diff --git a/web/styles/subscriptions.css b/web/styles/subscriptions.css
index 47347f18fb1..3d0b5dc435d 100644
--- a/web/styles/subscriptions.css
+++ b/web/styles/subscriptions.css
@@ -1775,3 +1775,10 @@
}
}
}
+
+#create_stream_name.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;
+}
diff --git a/web/templates/stream_settings/stream_creation_form.hbs b/web/templates/stream_settings/stream_creation_form.hbs
index f5e5255ba39..28a33f055b2 100644
--- a/web/templates/stream_settings/stream_creation_form.hbs
+++ b/web/templates/stream_settings/stream_creation_form.hbs
@@ -11,7 +11,7 @@
{{t "Channel name" }}
</label>
<input type="text" name="stream_name" id="create_stream_name" class="settings_text_input"
- placeholder="{{t 'Channel name' }}" value="" autocomplete="off" maxlength="{{ max_stream_name_length }}" />
+ placeholder="{{t 'Channel name' }}" value="" autocomplete="off" />
<div id="stream_name_error" class="stream_creation_error"></div>
</section>
<section id="create_stream_description_container">