FEATURE: Automatically select share URL (#16025)

The URL will be selected for easy copying immediately after the share
popup shows up.
This commit is contained in:
Bianca Nenciu 2022-02-24 03:21:20 +02:00 committed by GitHub
parent 582091a698
commit e0b683f98e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import { bufferedProperty } from "discourse/mixins/buffered-content";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import I18n from "I18n";
import Category from "discourse/models/category";
import { scheduleOnce } from "@ember/runloop";
export default Controller.extend(
ModalFunctionality,
@ -32,6 +33,17 @@ export default Controller.extend(
if (this.model && this.model.read_restricted) {
this.restrictedGroupWarning();
}
scheduleOnce("afterRender", this, this.selectUrl);
},
selectUrl() {
const input = document.querySelector("input.invite-link");
if (input && !this.site.mobileView) {
// if the input is auto-focused on mobile, iOS requires two taps of the copy button
input.setSelectionRange(0, this.url.length);
input.focus();
}
},
@discourseComputed("post.shareUrl", "topic.shareUrl")
@ -49,9 +61,9 @@ export default Controller.extend(
sources(topic) {
const privateContext =
this.siteSettings.login_required ||
(topic && topic.isPrivateMessage) ||
(topic && topic.invisible) ||
topic.category.read_restricted;
topic?.isPrivateMessage ||
topic?.invisible ||
topic?.category?.read_restricted;
return Sharing.activeSources(
this.siteSettings.share_links,

View File

@ -8,6 +8,7 @@
}
input,
.select-kit {
cursor: auto;
width: 100%;
margin-bottom: 0;
}