Salesforce Lightning JS behaviour

Related List

Icon-headed cards of child records with a View All footer — object relationships at a glance.

Documentation

Real scenarios

The component as it is used in a product — not a specimen grid.

The opportunity, unpacked

Two related lists side by side: add a contact with New, remove one from its ⋯ menu, and watch both counts keep honest.

The header tells the object

Same card anatomy, different tint and initial — you read the relationship before reading a word.

Contacts
Files
Tasks
Notes
(5) count
View all view-all

Important props

Important props
Prop Type Default What it does
icon-header slot 'object' The object’s small icon sits beside the card title and names the related object at a glance.
count number 'title' The record count rides in parentheses on the title: «Contacts (5)».
view-all footer 'link' The card footer’s View All link opens the list’s full view.
row-actions menu '⋯' Every row carries its own overflow menu: edit, delete, open.

Snippet

<article class="sflx-related">
    <header>
        <span class="sflx-rl-icon" data-object="contact">C</span>
        <h2>Contacts (3)</h2>
        <button class="sflx-btn" data-variant="neutral">New</button>
    </header>
    <ul>
        <li><b>Lena Hoffmann</b><span>lena@acme.example</span></li>
        <li><b>Emre Yilmaz</b><span>emre@acme.example</span></li>
    </ul>
    <footer><a href="#">View all</a></footer>
</article>

<style>
.sflx-related { border: 1px solid #DDDBDA; border-radius: .25rem; background: #fff; }
.sflx-related header { display: flex; align-items: center; gap: .5rem; padding: .75rem 1rem; }
.sflx-rl-icon { inline-size: 1.5rem; aspect-ratio: 1; display: grid; place-items: center;
                border-radius: .25rem; background: #0B5CAB; color: #fff; font-size: .7rem; }
.sflx-related ul li { display: grid; padding: .5rem 1rem; border-block-start: 1px solid #DDDBDA; }
</style>
// resources/js/pages/Opportunities/Related.tsx — an Inertia page (React
// flavor). The child records arrive from the backend as props; rendering is
// the RelatedList component from the React snippet.
import RelatedList from '@/components/RelatedList';

export default function OpportunityRelated() {
  // A real page would read its data: const { contacts, files } = usePage().props;
  return <RelatedList />;
}
// RelatedList.tsx — two icon-headed related-list cards (Contacts, Files)
// with honest counts, a New action, row overflow menus and View All footers.
// The markup mirrors the playground partial (sll-* classes).
import { type CSSProperties, useState } from 'react';
import '@nabuxai/ui-react/css';

type Person = { name: string; role: string; mail: string };
const POOL: Person[] = [
  { name: 'Elif Demir', role: 'Head of purchasing', mail: 'elif@acme.example' },
  { name: 'Lena Fischer', role: 'Technical reviewer', mail: 'lena@acme.example' },
  { name: 'Marco Benzi', role: 'Finance manager', mail: 'marco@acme.example' },
];
const FILES = [
  { name: 'Quote-2026.pdf', meta: '248 KB · yesterday' },
  { name: 'Contract-Bosporus.docx', meta: '1.1 MB · 3 days ago' },
];

const PATHS = {
  externalLink: 'M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5',
  edit: 'M4 20h4L19 9l-4-4L4 16zM13.5 6.5l4 4',
  trash: 'M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3',
  file: 'M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8zM14 3v5h5',
  chevronLeft: 'M15 6l-6 6 6 6',
};

const I = ({ d }: { d: string }) => (
  <svg className="nx-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor"
    strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d={d} /></svg>
);

export default function RelatedList() {
  const [people, setPeople] = useState<Person[]>(POOL.slice(0, 2));
  const [next, setNext] = useState(2);
  const [menuFor, setMenuFor] = useState<number | null>(null);

  const add = () => { setPeople([...people, POOL[next % POOL.length]]); setNext(next + 1); };
  const remove = (i: number) => { setPeople(people.filter((_, j) => j !== i)); setMenuFor(null); };

  return (
    <div className="sll-root">
      <div className="sll-row">
        <article className="sll-card" style={{ '--sll-tint': '#6739B7' } as CSSProperties}>
          <header className="sll-head">
            <span className="sll-tile" aria-hidden="true">C</span>
            <h3>Contacts ({people.length})</h3>
            <button type="button" className="sll-btn sll-new" onClick={add}>New</button>
          </header>
          <ul className="sll-list">
            {people.map((p, i) => (
              <li key={p.mail} className="sll-item">
                <div><b>{p.name}</b><span>{p.role} · {p.mail}</span></div>
                <span className="sll-rowmenu">
                  <button type="button" className="sll-dots" aria-haspopup="menu"
                    aria-expanded={menuFor === i} aria-label={'Actions for ' + p.name}
                    onClick={() => setMenuFor(menuFor === i ? null : i)}>⋯</button>
                  {menuFor === i && (
                    <nav className="sll-menu" role="menu">
                      <button type="button" role="menuitem" onClick={() => setMenuFor(null)}><I d={PATHS.externalLink} /> Open</button>
                      <button type="button" role="menuitem" onClick={() => setMenuFor(null)}><I d={PATHS.edit} /> Edit</button>
                      <button type="button" role="menuitem" data-tone="danger" onClick={() => remove(i)}><I d={PATHS.trash} /> Remove</button>
                    </nav>
                  )}
                </span>
              </li>
            ))}
          </ul>
          <footer className="sll-foot"><a href="#contacts">View all <I d={PATHS.chevronLeft} /></a></footer>
        </article>

        <article className="sll-card" style={{ '--sll-tint': '#FE9339' } as CSSProperties}>
          <header className="sll-head">
            <span className="sll-tile" aria-hidden="true">F</span>
            <h3>Files ({FILES.length})</h3>
          </header>
          <ul className="sll-list">
            {FILES.map((f) => (
              <li key={f.name} className="sll-item">
                <span className="sll-file">
                  <I d={PATHS.file} />
                  <div><b>{f.name}</b><span>{f.meta}</span></div>
                </span>
              </li>
            ))}
          </ul>
          <footer className="sll-foot"><a href="#files">View all <I d={PATHS.chevronLeft} /></a></footer>
        </article>
      </div>

      <style>{css}</style>
    </div>
  );
}

const css = `
.sll-root { font-family: 'Salesforce Sans', -apple-system, 'Segoe UI', Roboto, sans-serif; color: #181818;
  --sll-border: #DDDBDA; --sll-card: #FFFFFF; --sll-bg: #F3F3F3; --sll-blue: #0176D3;
  --sll-blue-soft: color-mix(in srgb, #0176D3 8%, #FFFFFF); --sll-muted: #706E6B; --sll-red: #BA0517; }
@media (prefers-color-scheme: dark) { .sll-root { color: #F3F3F3;
  --sll-border: #474747; --sll-card: #232323; --sll-bg: #181818; --sll-blue: #0D9DDA;
  --sll-blue-soft: color-mix(in srgb, #0D9DDA 16%, #232323); --sll-muted: #A5A5A5; --sll-red: #FE5C4C; } }
.sll-row { display: flex; flex-wrap: wrap; gap: 1rem; }
.sll-card { flex: 1 1 17rem; min-inline-size: 0; border: 1px solid var(--sll-border);
  border-radius: .25rem; background: var(--sll-card); display: grid; }
.sll-head { display: flex; align-items: center; gap: .5rem; padding: .7rem .9rem; }
.sll-tile { display: grid; place-items: center; inline-size: 1.5rem; block-size: 1.5rem;
  border-radius: .25rem; background: var(--sll-tint); color: #FFFFFF; font-size: .72rem; font-weight: 700; }
.sll-head h3 { margin: 0; font-size: .95rem; font-weight: 700; }
.sll-new { margin-inline-start: auto; }
.sll-list { margin: 0; padding: 0; list-style: none; }
.sll-item { display: flex; align-items: center; gap: .6rem; padding: .55rem .9rem; }
.sll-item + .sll-item { border-block-start: 1px solid var(--sll-border); }
.sll-item > div { min-inline-size: 0; flex: 1; }
.sll-item b { display: block; font-size: .85rem; font-weight: 600; }
.sll-item span { display: block; font-size: .76rem; color: var(--sll-muted); }
.sll-rowmenu { position: relative; flex: none; }
.sll-dots { border: 0; background: transparent; color: var(--sll-muted); cursor: pointer;
  padding: .1rem .35rem; border-radius: .25rem; font-weight: 700; }
.sll-dots:hover { background: var(--sll-blue-soft); color: var(--sll-blue); }
.sll-menu { position: absolute; z-index: 5; inset-inline-end: 0; inset-block-start: 1.5rem;
  min-inline-size: 8.5rem; padding: .2rem 0; border: 1px solid var(--sll-border); border-radius: .25rem;
  background: var(--sll-card); box-shadow: 0 2px 6px rgba(0, 0, 0, .14); }
.sll-menu button { display: flex; inline-size: 100%; align-items: center; gap: .45rem; padding: .4rem .75rem;
  border: 0; background: transparent; color: inherit; font: inherit; font-size: .8rem; cursor: pointer; text-align: start; }
.sll-menu button:hover { background: var(--sll-blue-soft); }
.sll-menu [data-tone='danger'] { color: var(--sll-red); }
.sll-foot { border-block-start: 1px solid var(--sll-border); padding: .5rem .9rem; }
.sll-foot a { color: var(--sll-blue); font-size: .8rem; font-weight: 600; text-decoration: none;
  display: inline-flex; align-items: center; gap: .25rem; }
.sll-file { display: flex; align-items: center; gap: .6rem; }
.sll-file .nx-icon { color: var(--sll-muted); }
.sll-btn { padding: .35rem .8rem; border: 1px solid var(--sll-border); border-radius: .25rem;
  background: var(--sll-card); color: var(--sll-blue); font: inherit; font-size: .78rem;
  font-weight: 600; cursor: pointer; }
.sll-btn:hover { background: var(--sll-blue-soft); }
`;
<!-- RelatedList.vue — two icon-headed related-list cards (Contacts, Files)
     with honest counts, a New action, row overflow menus and View All
     footers. Markup mirrors the playground partial (sll-* classes). -->
<script setup lang="ts">
import { ref } from 'vue';

interface Person { name: string; role: string; mail: string }
const pool: Person[] = [
  { name: 'Elif Demir', role: 'Head of purchasing', mail: 'elif@acme.example' },
  { name: 'Lena Fischer', role: 'Technical reviewer', mail: 'lena@acme.example' },
  { name: 'Marco Benzi', role: 'Finance manager', mail: 'marco@acme.example' },
];
const files = [
  { name: 'Quote-2026.pdf', meta: '248 KB · yesterday' },
  { name: 'Contract-Bosporus.docx', meta: '1.1 MB · 3 days ago' },
];

const people = ref<Person[]>(pool.slice(0, 2));
const next = ref(2);
const menuFor = ref<number | null>(null);

const add = () => { people.value = [...people.value, pool[next.value % pool.length]]; next.value++; };
const remove = (i: number) => { people.value = people.value.filter((_, j) => j !== i); menuFor.value = null; };
</script>

<template>
  <div class="sll-root">
    <div class="sll-row">
      <article class="sll-card" style="--sll-tint: #6739B7">
        <header class="sll-head">
          <span class="sll-tile" aria-hidden="true">C</span>
          <h3>Contacts ({{ people.length }})</h3>
          <button type="button" class="sll-btn sll-new" @click="add">New</button>
        </header>
        <ul class="sll-list">
          <li v-for="(p, i) in people" :key="p.mail" class="sll-item">
            <div><b>{{ p.name }}</b><span>{{ p.role }} · {{ p.mail }}</span></div>
            <span class="sll-rowmenu">
              <button type="button" class="sll-dots" aria-haspopup="menu"
                :aria-expanded="menuFor === i" :aria-label="'Actions for ' + p.name"
                @click="menuFor = menuFor === i ? null : i">⋯</button>
              <nav v-if="menuFor === i" class="sll-menu" role="menu">
                <button type="button" role="menuitem" @click="menuFor = null">Open</button>
                <button type="button" role="menuitem" @click="menuFor = null">Edit</button>
                <button type="button" role="menuitem" data-tone="danger" @click="remove(i)">Remove</button>
              </nav>
            </span>
          </li>
        </ul>
        <footer class="sll-foot"><a href="#contacts">View all ›</a></footer>
      </article>

      <article class="sll-card" style="--sll-tint: #FE9339">
        <header class="sll-head">
          <span class="sll-tile" aria-hidden="true">F</span>
          <h3>Files ({{ files.length }})</h3>
        </header>
        <ul class="sll-list">
          <li v-for="f in files" :key="f.name" class="sll-item">
            <span class="sll-file"><div><b>{{ f.name }}</b><span>{{ f.meta }}</span></div></span>
          </li>
        </ul>
        <footer class="sll-foot"><a href="#files">View all ›</a></footer>
      </article>
    </div>
  </div>
</template>

<style scoped>
.sll-root { font-family: 'Salesforce Sans', -apple-system, 'Segoe UI', Roboto, sans-serif; color: #181818;
  --sll-border: #DDDBDA; --sll-card: #FFFFFF; --sll-bg: #F3F3F3; --sll-blue: #0176D3;
  --sll-blue-soft: color-mix(in srgb, #0176D3 8%, #FFFFFF); --sll-muted: #706E6B; --sll-red: #BA0517; }
@media (prefers-color-scheme: dark) { .sll-root { color: #F3F3F3;
  --sll-border: #474747; --sll-card: #232323; --sll-bg: #181818; --sll-blue: #0D9DDA;
  --sll-blue-soft: color-mix(in srgb, #0D9DDA 16%, #232323); --sll-muted: #A5A5A5; --sll-red: #FE5C4C; } }
.sll-row { display: flex; flex-wrap: wrap; gap: 1rem; }
.sll-card { flex: 1 1 17rem; min-inline-size: 0; border: 1px solid var(--sll-border);
  border-radius: .25rem; background: var(--sll-card); display: grid; }
.sll-head { display: flex; align-items: center; gap: .5rem; padding: .7rem .9rem; }
.sll-tile { display: grid; place-items: center; inline-size: 1.5rem; block-size: 1.5rem;
  border-radius: .25rem; background: var(--sll-tint); color: #FFFFFF; font-size: .72rem; font-weight: 700; }
.sll-head h3 { margin: 0; font-size: .95rem; font-weight: 700; }
.sll-new { margin-inline-start: auto; }
.sll-list { margin: 0; padding: 0; list-style: none; }
.sll-item { display: flex; align-items: center; gap: .6rem; padding: .55rem .9rem; }
.sll-item + .sll-item { border-block-start: 1px solid var(--sll-border); }
.sll-item > div { min-inline-size: 0; flex: 1; }
.sll-item b { display: block; font-size: .85rem; font-weight: 600; }
.sll-item span { display: block; font-size: .76rem; color: var(--sll-muted); }
.sll-rowmenu { position: relative; flex: none; }
.sll-dots { border: 0; background: transparent; color: var(--sll-muted); cursor: pointer;
  padding: .1rem .35rem; border-radius: .25rem; font-weight: 700; }
.sll-dots:hover { background: var(--sll-blue-soft); color: var(--sll-blue); }
.sll-menu { position: absolute; z-index: 5; inset-inline-end: 0; inset-block-start: 1.5rem;
  min-inline-size: 8.5rem; padding: .2rem 0; border: 1px solid var(--sll-border); border-radius: .25rem;
  background: var(--sll-card); box-shadow: 0 2px 6px rgba(0, 0, 0, .14); }
.sll-menu button { display: flex; inline-size: 100%; padding: .4rem .75rem; border: 0;
  background: transparent; color: inherit; font: inherit; font-size: .8rem; cursor: pointer; text-align: start; }
.sll-menu button:hover { background: var(--sll-blue-soft); }
.sll-menu [data-tone='danger'] { color: var(--sll-red); }
.sll-foot { border-block-start: 1px solid var(--sll-border); padding: .5rem .9rem; }
.sll-foot a { color: var(--sll-blue); font-size: .8rem; font-weight: 600; text-decoration: none; }
.sll-file { display: flex; align-items: center; gap: .6rem; }
.sll-file div { min-inline-size: 0; }
.sll-btn { padding: .35rem .8rem; border: 1px solid var(--sll-border); border-radius: .25rem;
  background: var(--sll-card); color: var(--sll-blue); font: inherit; font-size: .78rem;
  font-weight: 600; cursor: pointer; }
.sll-btn:hover { background: var(--sll-blue-soft); }
</style>
<!-- RelatedList.svelte — two icon-headed related-list cards (Contacts,
     Files) with honest counts, a New action, row overflow menus and View All
     footers. Markup mirrors the playground partial (sll-* classes). -->
<script lang="ts">
  interface Person { name: string; role: string; mail: string }
  const pool: Person[] = [
    { name: 'Elif Demir', role: 'Head of purchasing', mail: 'elif@acme.example' },
    { name: 'Lena Fischer', role: 'Technical reviewer', mail: 'lena@acme.example' },
    { name: 'Marco Benzi', role: 'Finance manager', mail: 'marco@acme.example' },
  ];
  const files = [
    { name: 'Quote-2026.pdf', meta: '248 KB · yesterday' },
    { name: 'Contract-Bosporus.docx', meta: '1.1 MB · 3 days ago' },
  ];

  let people = $state<Person[]>(pool.slice(0, 2));
  let next = $state(2);
  let menuFor = $state<number | null>(null);

  const add = () => { people = [...people, pool[next % pool.length]]; next++; };
  const remove = (i: number) => { people = people.filter((_, j) => j !== i); menuFor = null; };
</script>

<div class="sll-root">
  <div class="sll-row">
    <article class="sll-card" style:--sll-tint="#6739B7">
      <header class="sll-head">
        <span class="sll-tile" aria-hidden="true">C</span>
        <h3>Contacts ({people.length})</h3>
        <button type="button" class="sll-btn sll-new" onclick={add}>New</button>
      </header>
      <ul class="sll-list">
        {#each people as p, i (p.mail)}
          <li class="sll-item">
            <div><b>{p.name}</b><span>{p.role} · {p.mail}</span></div>
            <span class="sll-rowmenu">
              <button type="button" class="sll-dots" aria-haspopup="menu"
                aria-expanded={menuFor === i} aria-label={'Actions for ' + p.name}
                onclick={() => (menuFor = menuFor === i ? null : i)}>⋯</button>
              {#if menuFor === i}
                <nav class="sll-menu" role="menu">
                  <button type="button" role="menuitem" onclick={() => (menuFor = null)}>Open</button>
                  <button type="button" role="menuitem" onclick={() => (menuFor = null)}>Edit</button>
                  <button type="button" role="menuitem" data-tone="danger" onclick={() => remove(i)}>Remove</button>
                </nav>
              {/if}
            </span>
          </li>
        {/each}
      </ul>
      <footer class="sll-foot"><a href="#contacts">View all ›</a></footer>
    </article>

    <article class="sll-card" style:--sll-tint="#FE9339">
      <header class="sll-head">
        <span class="sll-tile" aria-hidden="true">F</span>
        <h3>Files ({files.length})</h3>
      </header>
      <ul class="sll-list">
        {#each files as f (f.name)}
          <li class="sll-item">
            <span class="sll-file"><div><b>{f.name}</b><span>{f.meta}</span></div></span>
          </li>
        {/each}
      </ul>
      <footer class="sll-foot"><a href="#files">View all ›</a></footer>
    </article>
  </div>
</div>

<style>
.sll-root { font-family: 'Salesforce Sans', -apple-system, 'Segoe UI', Roboto, sans-serif; color: #181818;
  --sll-border: #DDDBDA; --sll-card: #FFFFFF; --sll-bg: #F3F3F3; --sll-blue: #0176D3;
  --sll-blue-soft: color-mix(in srgb, #0176D3 8%, #FFFFFF); --sll-muted: #706E6B; --sll-red: #BA0517; }
@media (prefers-color-scheme: dark) { .sll-root { color: #F3F3F3;
  --sll-border: #474747; --sll-card: #232323; --sll-bg: #181818; --sll-blue: #0D9DDA;
  --sll-blue-soft: color-mix(in srgb, #0D9DDA 16%, #232323); --sll-muted: #A5A5A5; --sll-red: #FE5C4C; } }
.sll-row { display: flex; flex-wrap: wrap; gap: 1rem; }
.sll-card { flex: 1 1 17rem; min-inline-size: 0; border: 1px solid var(--sll-border);
  border-radius: .25rem; background: var(--sll-card); display: grid; }
.sll-head { display: flex; align-items: center; gap: .5rem; padding: .7rem .9rem; }
.sll-tile { display: grid; place-items: center; inline-size: 1.5rem; block-size: 1.5rem;
  border-radius: .25rem; background: var(--sll-tint); color: #FFFFFF; font-size: .72rem; font-weight: 700; }
.sll-head h3 { margin: 0; font-size: .95rem; font-weight: 700; }
.sll-new { margin-inline-start: auto; }
.sll-list { margin: 0; padding: 0; list-style: none; }
.sll-item { display: flex; align-items: center; gap: .6rem; padding: .55rem .9rem; }
.sll-item + .sll-item { border-block-start: 1px solid var(--sll-border); }
.sll-item > div { min-inline-size: 0; flex: 1; }
.sll-item b { display: block; font-size: .85rem; font-weight: 600; }
.sll-item span { display: block; font-size: .76rem; color: var(--sll-muted); }
.sll-rowmenu { position: relative; flex: none; }
.sll-dots { border: 0; background: transparent; color: var(--sll-muted); cursor: pointer;
  padding: .1rem .35rem; border-radius: .25rem; font-weight: 700; }
.sll-dots:hover { background: var(--sll-blue-soft); color: var(--sll-blue); }
.sll-menu { position: absolute; z-index: 5; inset-inline-end: 0; inset-block-start: 1.5rem;
  min-inline-size: 8.5rem; padding: .2rem 0; border: 1px solid var(--sll-border); border-radius: .25rem;
  background: var(--sll-card); box-shadow: 0 2px 6px rgba(0, 0, 0, .14); }
.sll-menu button { display: flex; inline-size: 100%; padding: .4rem .75rem; border: 0;
  background: transparent; color: inherit; font: inherit; font-size: .8rem; cursor: pointer; text-align: start; }
.sll-menu button:hover { background: var(--sll-blue-soft); }
.sll-menu [data-tone='danger'] { color: var(--sll-red); }
.sll-foot { border-block-start: 1px solid var(--sll-border); padding: .5rem .9rem; }
.sll-foot a { color: var(--sll-blue); font-size: .8rem; font-weight: 600; text-decoration: none; }
.sll-file { display: flex; align-items: center; gap: .6rem; }
.sll-file div { min-inline-size: 0; }
.sll-btn { padding: .35rem .8rem; border: 1px solid var(--sll-border); border-radius: .25rem;
  background: var(--sll-card); color: var(--sll-blue); font: inherit; font-size: .78rem;
  font-weight: 600; cursor: pointer; }
.sll-btn:hover { background: var(--sll-blue-soft); }
</style>