Merge pull request #37151 from ShrihariMahabal/fix-add-doc-button-for-long-doctype-name

This commit is contained in:
Suraj Shetty 2026-02-24 18:44:59 +05:30 committed by GitHub
commit 4ef2a42550
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -291,8 +291,9 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
set_primary_action() {
if (this.can_create && !frappe.boot.read_only) {
const doctype_name = __(frappe.router.doctype_layout) || __(this.doctype);
const add_button_label = __("Add {0}", [doctype_name], "Primary action in list view");
const create_button = this.page.set_primary_action(
__("Add {0}", [doctype_name], "Primary action in list view"),
add_button_label,
() => {
if (this.settings.primary_action) {
this.settings.primary_action();
@ -304,12 +305,26 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
);
if (frappe.is_mobile()) {
create_button.append(__("Add"));
} else {
this._trim_primary_action_if_overflow(create_button, add_button_label);
}
} else {
this.page.clear_primary_action();
}
}
_trim_primary_action_if_overflow(btn, add_button_label) {
const container = this.page.wrapper.find(".page-head-content")[0];
if (!container || !btn[0]) return;
const containerRect = container.getBoundingClientRect();
const btnRect = btn[0].getBoundingClientRect();
if (btnRect.right > containerRect.right) {
const short_label = __("Add");
btn.attr("title", add_button_label).tooltip();
btn.find("span").text(short_label);
}
}
make_new_doc() {
const doctype = this.doctype;
const options = {};