Skip to content

feat(mjml-social): add border attribute to mj-social-element#3105

Open
danfitz36 wants to merge 1 commit into
mjmlio:masterfrom
danfitz36:feat/mjml-social-element-border-attribute
Open

feat(mjml-social): add border attribute to mj-social-element#3105
danfitz36 wants to merge 1 commit into
mjmlio:masterfrom
danfitz36:feat/mjml-social-element-border-attribute

Conversation

@danfitz36
Copy link
Copy Markdown

Fixes #2466.

Email accessibility tooling (Email on Acid, Litmus) flags <img> tags in social blocks for missing border attributes. mj-image already supports a border attribute that renders as CSS on the resulting <img>; mj-social-element did not, leaving no way to set or default it without copying the rendered HTML out by hand.

Changes

  • packages/mjml-social/src/SocialElement.js
    • Add border: 'string' to allowedAttributes
    • Add border: '0' to defaultAttributes (matches mj-image's default)
    • Add border: this.getAttribute('border') to the img styles in getStyles()
  • packages/mjml-social/src/Social.js
    • Add border: 'string' to allowedAttributes
    • Add border to the cascade list in getSocialElementAttributes so a single declaration on mj-social applies to every child. Element-level borders still take precedence.
  • packages/mjml-social/README.md
    • New border rows in both attribute tables
  • packages/mjml/test/social-border.test.js (new)
    • Four cases: default 0 on every element, explicit element override, parent cascade, and element-overrides-cascade

Sample rendered output

With:

<mj-social border="1px solid #ccc">
  <mj-social-element name="facebook" href="https://mjml.io/" />
  <mj-social-element name="x" href="https://mjml.io/" border="2px solid red" />
  <mj-social-element name="linkedin" href="https://mjml.io/" />
</mj-social>

The three <img> tags emit:

  • style="border:1px solid #ccc;border-radius:3px;display:block;" (cascaded)
  • style="border:2px solid red;border-radius:3px;display:block;" (element override)
  • style="border:1px solid #ccc;border-radius:3px;display:block;" (cascaded)

Verification

  • yarn build ✓ all packages
  • yarn test ✓ 74 → 78 (the 4 new cases)
  • Lint clean on changed files

Email accessibility tooling (Email on Acid, Litmus) flags <img> tags
in social blocks for missing border attributes. mj-image already
supports a `border` attribute that lands as CSS on the rendered
<img>; mj-social-element did not, leaving no way to set or default
it without copying the rendered HTML out by hand.

Adds `border` to mj-social-element with default `0` (matching
mj-image's default). Also exposes `border` on the mj-social parent
and cascades it through getSocialElementAttributes so a single
border declaration applies to every child element. Element-level
borders still take precedence over the cascaded parent value.

README attribute tables updated for both components.

Fix mjmlio#2466.
Sign up for free to 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.

mj-social should have border attribute

1 participant