UX: focus category name when editing category (#9795)

This commit is contained in:
Joffrey JAFFEUX 2020-05-15 18:27:06 +02:00 committed by GitHub
parent b07f1bfd93
commit 7edd312f85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { isEmpty } from "@ember/utils"; import { isEmpty } from "@ember/utils";
import { not } from "@ember/object/computed"; import { not } from "@ember/object/computed";
import { later } from "@ember/runloop";
import { buildCategoryPanel } from "discourse/components/edit-category-panel"; import { buildCategoryPanel } from "discourse/components/edit-category-panel";
import { categoryBadgeHTML } from "discourse/helpers/category-link"; import { categoryBadgeHTML } from "discourse/helpers/category-link";
import Category from "discourse/models/category"; import Category from "discourse/models/category";
@ -12,6 +13,12 @@ export default buildCategoryPanel("general", {
this.foregroundColors = ["FFFFFF", "000000"]; this.foregroundColors = ["FFFFFF", "000000"];
}, },
didInsertElement() {
this._super(...arguments);
this._focusCategoryName();
},
canSelectParentCategory: not("category.isUncategorizedCategory"), canSelectParentCategory: not("category.isUncategorizedCategory"),
uncategorizedSiteSettingLink: Discourse.getURL( uncategorizedSiteSettingLink: Discourse.getURL(
"/admin/site_settings/category/all_results?filter=allow_uncategorized_topics" "/admin/site_settings/category/all_results?filter=allow_uncategorized_topics"
@ -101,5 +108,14 @@ export default buildCategoryPanel("general", {
window.open(this.get("category.topic_url"), "_blank").focus(); window.open(this.get("category.topic_url"), "_blank").focus();
return false; return false;
} }
},
_focusCategoryName() {
later(() => {
if (this.element && !this.isDestroying && !this.isDestroyed) {
const categoryName = this.element.querySelector(".category-name");
categoryName && categoryName.focus();
}
}, 25);
} }
}); });