Rbtz.CredoChecks.Warning.PhxClickAwayWithoutId (rbtz_credo_checks v0.3.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

Requires every element with phx-click-away to also carry an id attribute.

phx-click-away registers a document-level click listener that fires when the user clicks outside the element. LiveView uses the element's DOM id to match it across patches; without it, the listener can be orphaned, fire twice, or be lost entirely after re-render — leading to menus that won't close (or close at the wrong time).

The check inspects every ~H sigil and every .heex template referenced via embed_templates. It walks each opening tag (across multiple lines) and flags those that carry phx-click-away= without id=.

Bad

<div phx-click-away="close">...</div>

Good

<div id="menu" phx-click-away="close">...</div>

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.