Skip to content

Commit b0996a7

Browse files
committed
first close reason should be autofocused upon opening the post closure modal
1 parent 4ce8294 commit b0996a7

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

app/assets/javascripts/closure.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ document.addEventListener('DOMContentLoaded', async () => {
4444
QPixel.createNotification('danger', `<strong>Failed:</strong> ${req.status}`);
4545
}
4646
});
47+
48+
QPixel.DOM?.watchClass('.js-close-box.is-active', (target) => {
49+
const reasonInput = target.querySelector('input[name="close-reason"]');
50+
51+
if (QPixel.DOM?.isHTMLElement(reasonInput)) {
52+
reasonInput.focus();
53+
}
54+
});
4755
});

app/views/posts/_close_modal.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="post--action-dialog js-close-box">
99
<div class="widget">
1010
<div class="widget--header">Why should this post be closed?</div>
11-
<% CloseReason.active.each do |reason| %>
11+
<% CloseReason.active.each_with_index do |reason, idx| %>
1212
<div class="widget--body">
1313
<div class="grid">
1414
<div class="grid--cell">
@@ -17,6 +17,7 @@
1717
name="close-reason"
1818
value="<%= reason.id %>"
1919
id="close-reason-<%= reason.id %>"
20+
<%= 'checked' if idx.zero? %>
2021
data-rop="<%= reason.requires_other_post %>">
2122
</div>
2223
<div class="grid--cell is-flexible">

0 commit comments

Comments
 (0)