diff --git a/app/javascript/controllers/reaction_emoji_controller.js b/app/javascript/controllers/reaction_emoji_controller.js new file mode 100644 index 000000000..b792a2a0c --- /dev/null +++ b/app/javascript/controllers/reaction_emoji_controller.js @@ -0,0 +1,10 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + static targets = [ "input" ] + + insertEmoji(event) { + const emojiChar = event.target.getAttribute("data-emoji") + this.inputTarget.value = emojiChar + } +} diff --git a/app/views/cards/comments/reactions/_menu.html.erb b/app/views/cards/comments/reactions/_menu.html.erb index 75d2d2804..9d2677b4b 100644 --- a/app/views/cards/comments/reactions/_menu.html.erb +++ b/app/views/cards/comments/reactions/_menu.html.erb @@ -6,7 +6,7 @@
<% EmojiHelper::REACTIONS.each do |character, title| %> - <%= tag.button character, title: title, class: "reactions__emoji-btn btn btn--circle", data: { emoji: character } %> + <%= tag.button character, title: title, class: "reactions__emoji-btn btn btn--circle", data: { action: "reaction-emoji#insertEmoji", emoji: character } %> <% end %>
diff --git a/app/views/cards/comments/reactions/new.html.erb b/app/views/cards/comments/reactions/new.html.erb index 9538e713e..8096b9913 100644 --- a/app/views/cards/comments/reactions/new.html.erb +++ b/app/views/cards/comments/reactions/new.html.erb @@ -2,14 +2,14 @@ <%= form_with model: [ @comment.card, @comment, Reaction.new ], class: "reaction reaction__form expanded", html: { aria: { label: "New reaction" } }, - data: { controller: "form", turbo_frame: dom_id(@comment, :reacting), action: "keydown.esc->form#cancel submit->form#preventEmptySubmit" } do |form| %> + data: { controller: "form reaction-emoji", turbo_frame: dom_id(@comment, :reacting), action: "keydown.esc->form#cancel submit->form#preventEmptySubmit" } do |form| %> <%= render "cards/comments/reactions/menu", comment: @comment %>