Skip to content

Commit cdde07b

Browse files
committed
image upload input should take focus when the modal is opened
1 parent e2a2ddc commit cdde07b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

app/assets/javascripts/posts.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ $(() => {
4848
$uploadForm.trigger('submit')
4949
});
5050

51+
new MutationObserver((records) => {
52+
for (const record of records) {
53+
if (record.target instanceof HTMLElement &&
54+
record.target.id === 'markdown-image-upload' &&
55+
record.target.classList.contains('is-active')) {
56+
const fileInput = record.target.querySelector('input[type="file"]');
57+
58+
if (fileInput instanceof HTMLInputElement) {
59+
fileInput.focus();
60+
}
61+
}
62+
}
63+
}).observe(document, {
64+
attributeFilter: ['class'],
65+
subtree: true,
66+
});
67+
5168
$uploadForm.on('submit', async (evt) => {
5269
evt.preventDefault();
5370

0 commit comments

Comments
 (0)