Skip to content

Widen TableDefault class attr to :any so class={[...]} idiom works - #566

Closed
mdon wants to merge 1 commit into
BeamLabEU:devfrom
mdon:fix-table-default-class-attr-list
Closed

Widen TableDefault class attr to :any so class={[...]} idiom works#566
mdon wants to merge 1 commit into
BeamLabEU:devfrom
mdon:fix-table-default-class-attr-list

Conversation

@mdon

@mdonmdon commented May 22, 2026

Copy link
Copy Markdown
Contributor

Summary

The seven attr :class, :string declarations on the
PhoenixKitWeb.Components.Core.TableDefault.* family reject
Phoenix-idiomatic class={[...]} at compile time, but every
component already accepts lists internally — they wrap @class
inside another list that Phoenix flattens. The :string declaration
is a stale guard from before the internal usage settled.

Surfaced when phoenix_kit_ai's endpoint list table uses a
conditional-class list:

warning: attribute "class" in component
PhoenixKitWeb.Components.Core.TableDefault.table_default_row/1
must be a :string, got: [if !endpoint.enabled do "opacity-60" end, ...]
endpoints.html.heex:241

Fix applied uniformly to all seven components in the file
(table_default/1, table_default_header/1, table_default_row/1,
table_default_body/1, table_default_cell/1,
table_default_header_cell/1, table_default_search/1) so future
consumers don't relitigate the same warning per-component. Defaults
unchanged (still string literals).

Notes

  • No behavior change for existing callers passing strings.
  • New behavior: class={[...]} and class={["a", false, "b"]} now
    compile cleanly, with Phoenix's standard nil/false filtering and
    flattening applied at render time.

Test plan

  • mix compile --warnings-as-errors clean
  • mix format --check-formatted clean
  • mix credo --strict clean on touched file

`attr :class, :string` rejects a list at compile time, but every
TableDefault component already accepts lists internally — they
wrap `@class` inside another list that Phoenix flattens. The
:string declaration is just a stale guard from before the
internal usage settled.
Surfaces as a warning when a consumer uses the Phoenix-standard
`class={[if(...), if(...)]}` idiom for conditional classes:
warning: attribute "class" in component
PhoenixKitWeb.Components.Core.TableDefault.table_default_row/1
must be a :string, got: [if !endpoint.enabled do
"opacity-60" end, ...]
endpoints.html.heex:241
Triggered by `phoenix_kit_ai`'s endpoint list table (the only
current external consumer using a conditional class list). Same
fix applied uniformly to all seven `attr :class` declarations in
the file (`table_default/1`, `table_default_header/1`,
`table_default_row/1`, `table_default_body/1`,
`table_default_cell/1`, `table_default_header_cell/1`,
`table_default_search/1`) so future consumers don't relitigate
the same warning per-component.
Defaults are kept as strings (`""` and `"bg-base-300"`) — only
the type widens.
@mdon

mdon commented May 22, 2026

Copy link
Copy Markdown
ContributorAuthor

Folding into #565 — bundling phoenix_kit follow-ups into one PR per module per session. The same one-line commit will be cherry-picked there.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@mdon