Skip to content

Commit

Permalink
FIX: focusing input displayed after clicking on a link more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux committed Jun 13, 2018
1 parent 4a9dadb commit 4e0c06a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
15 changes: 15 additions & 0 deletions app/assets/javascripts/discourse/components/link-to-input.js.es6
@@ -0,0 +1,15 @@
export default Ember.Component.extend({
showInput: false,

click() {
this.get("onClick")();

Ember.run.schedule("afterRender", () => {
this.$()
.find("input")
.focus();
});

return false;
}
});
@@ -0,0 +1,5 @@
{{#if showInput}}
{{yield}}
{{else}}
<a href>{{i18n key}}</a>
{{/if}}
8 changes: 3 additions & 5 deletions app/assets/javascripts/discourse/templates/composer.hbs
Expand Up @@ -24,11 +24,9 @@
{{/unless}}

{{#if canEdit}}
{{#if showEditReason}}
{{text-field autofocus="true" value=editReason tabindex="7" id="edit-reason" maxlength="255" placeholderKey="composer.edit_reason_placeholder"}}
{{else}}
<a {{action "displayEditReason"}} class="display-edit-reason">{{i18n 'composer.show_edit_reason'}}</a>
{{/if}}
{{#link-to-input onClick=(action "displayEditReason") showInput=showEditReason key="composer.show_edit_reason" class="display-edit-reason"}}
{{text-field value=editReason tabindex="7" id="edit-reason" maxlength="255" placeholderKey="composer.edit_reason_placeholder"}}
{{/link-to-input}}
{{/if}}
</div>
{{composer-toggles composeState=model.composeState
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/common/base/compose.scss
Expand Up @@ -157,6 +157,10 @@
font-style: italic;
}

.display-edit-reason {
display: inline;
}

#edit-reason {
margin: 4px;
}
Expand Down

1 comment on commit 4e0c06a

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/regression-edit-reason-input-not-autofocussed/64779/4

Please sign in to comment.