সরিয়ে দিতে সোয়াইপ করুন

মোবাইল অ্যাপ্লিকেশনে সোয়াইপ-টু-রিমুভ প্যাটার্ন সাধারণ হলেও, ওয়েবে এটি পরিষ্কারভাবে প্রয়োগ করা চ্যালেঞ্জিং হতে পারে। CSS স্ক্রল স্ন্যাপ ব্যবহার করে, আপনি একটি মসৃণ, নেটিভ-ফিলিং সোয়াইপ ইন্টারঅ্যাকশন তৈরি করতে পারেন যা সরাসরি ব্রাউজারের স্ক্রলিং ইঞ্জিনে হুক করে। এটি জটিল জাভাস্ক্রিপ্ট জেসচার লাইব্রেরির প্রয়োজন ছাড়াই উচ্চ পারফর্ম্যান্স এবং ফিজিক্স-ভিত্তিক মোমেন্টাম নিশ্চিত করে।

একক-অ্যাকশন সোয়াইপের (সরানো, আর্কাইভ করা, 'পড়া হয়েছে' হিসেবে চিহ্নিত করা, স্নুজ করা) ক্ষেত্রে একই প্যাটার্ন কাজ করে। অ্যাকশন ভিজ্যুয়াল পরিবর্তন হয়; মেকানিক্স নয়।

আপনি যদি সোয়াইপ করার সময় অটোমেটিক কোনও অ্যাকশন কমিট না করে, অ্যাকশন বোতামের সেট বা সাইড মেনু স্ন্যাপ ওপেন করার জন্য অনুভূমিক সোয়াইপ করতে চান, তাহলে দেখার জন্য সোয়াইপ করুন বিকল্প দেখুন।

কীভাবে প্রয়োগ করতে হয়

কম্পোনেন্টে দুটি লেয়ার আছে: একটি তালিকা (<ul>) এবং এর মধ্যে থাকা আইটেম। প্রতিটি আইটেম একটি বাইরের <li>, একটি ভিতরের স্ক্রল ট্র্যাক (স্ন্যাপ পয়েন্ট সহ স্ক্রল কন্টেনার) এবং একটি কন্টেন্ট এলিমেন্ট (দৃশ্যমান সারি) হিসাবে স্ট্রাকচার করা হয়। অ্যাকশনের প্রকাশ করা UI (ট্র্যাশ আইকন, আর্কাইভ লেবেল ইত্যাদি) কন্টেন্টের যেকোনও পাশে থাকে। তালিকার নিজস্ব শেয়ার করা ওয়্যারিং (লেজি আইটেম সেট-আপ, নতুন যোগ করা আইটেম বেছে নেওয়া) আছে; প্রতিটি আইটেমের নিজস্ব সোয়াইপ শনাক্তকরণ আছে।

ধাপ ১: ট্র্যাক ও কন্টেন্ট সহ তালিকা মার্ক-আপ করুন

<ul class="SwipeableList">
  <li id="list-item-1" class="SwipeableList-item">
    <div class="SwipeableList-track">
      <div class="SwipeableList-content">Item One</div>
    </div>
  </li>
  <li id="list-item-2" class="SwipeableList-item">
    <div class="SwipeableList-track">
      <div class="SwipeableList-content">Item Two</div>
    </div>
  </li>
  <!-- ...more items... -->
</ul>

ধাপ ২: তিনটি স্ন্যাপ পয়েন্ট সহ হরাইজন্টাল স্ন্যাপ কন্টেনার হিসেবে ট্র্যাক কনফিগার করুন

ট্র্যাকে তিনটি ফুল-উইডথ কলাম আছে: বাঁদিকের স্পেসার (::before), কন্টেন্ট এবং ডানদিকের স্পেসার (::after)। স্পেসারে স্ন্যাপ করার অর্থ হল কন্টেন্ট সম্পূর্ণভাবে অফ-স্ক্রিন, যা সোয়াইপ করার পরে বাকি পজিশন।

ট্র্যাক কনফিগারেশন তালিকা আইটেমে .is-initialized ক্লাসের পিছনে গেট করা আছে। JS রো আপগ্রেড করার আগে, আইটেমটি কোনও অনুভূমিক স্ক্রলার ছাড়াই সাধারণ কন্টেন্ট হিসেবে রেন্ডার করে। সোয়াইপ শনাক্ত করে এমন জাভাস্ক্রিপ্ট ওয়্যার আপ করা হয়ে গেলে, ক্লাসটি ধাপ ৪-এ যোগ করা হয়। এটি নিশ্চিত করে যে কার্যকারিতা প্রস্তুত হওয়ার আগে ব্যবহারকারী সোয়াইপ করতে পারবেন না।

.SwipeableList {
  list-style: none;
}

.SwipeableList-item {
  /* Establishes a containing block for the absolutely positioned action
     icons (Step 3) and clips overflow during the row's removal
     animation (Step 4). */
  contain: content;
}

/* The track only becomes a scroll snap container after JS upgrades
   the row by adding `.is-initialized` (see Step 4). */
.SwipeableList-item.is-initialized .SwipeableList-track {
  /* Three full-width columns: left spacer | content | right spacer.
     Width is 100% of the track, so each column fills the viewport row. */
  display: grid;
  grid-template-columns: 100% 100% 100%;

  /* Horizontal scroll only; vertical overflow is clipped so the
     reveal stays inside the row. */
  overflow: scroll clip;

  /* Prevent the swipe from chaining into the page scroll or browser
     back-gesture on iOS/Android. */
  overscroll-behavior-x: none;

  /* Hide the scrollbar; the gesture is the affordance. */
  scrollbar-width: none;

  /* `mandatory` ensures the track always rests on a snap point
     (spacer or content), never partially scrolled. */
  scroll-snap-type: x mandatory;
}

/* Spacers act as the left and right snap targets, AND carry the action's
   reveal color. As the user swipes, the colored spacer slides into view,
   which is what the user sees behind the content. */
.SwipeableList-item.is-initialized .SwipeableList-track::before,
.SwipeableList-item.is-initialized .SwipeableList-track::after {
  content: '';

  /* `scroll-snap-align` is required to make this a valid snap target,
     but the specific value (`start`/`center`/`end`) doesn't matter here
     because each snap point spans the full width of the scroll
     container, so all alignments resolve to the same resting position. */
  scroll-snap-align: start;

  /* `hsl(0 65% 50%)` is an example value; pick whatever fits your
     design (red here signals "delete"; use a different color for
     archive, mark-as-read, etc.). */
  background-color: hsl(0 65% 50%);
}

.SwipeableList-content {
  /* The content sits above the action icons (Step 3), so it covers
     them until the user swipes. */
  position: relative;
  z-index: 2;

  /* Required to make the content a valid snap target (its resting
     position). As with the spacers above, the specific value doesn't
     matter because the snap points are full-width. */
  scroll-snap-align: start;

  /* The content must paint over the revealed spacer color. */
  background: Canvas;

  /* Row separator (example value; customize to taste). */
  border-bottom: 1px solid #eee;
}

/* Gate `scroll-initial-target` behind `.is-initialized` so it only
   applies once the track is actually a scroll container. Setting it on
   the content before then would let the property walk up to the nearest
   scrollable ancestor (typically the document) and shift the page's
   initial scroll position to bring this row's content into view. With
   the gate, the rule is only live when the row's own track can satisfy
   it, so the initial scroll happens inside the track as intended. */
.SwipeableList-item.is-initialized .SwipeableList-content {
  scroll-initial-target: nearest;
}

/* The track is the focusable scroll container, but its overflow is clipped
   so a default focus ring on the track itself would be invisible. Project
   the focus affordance onto the content element (which paints above the
   track) using `:focus-visible` on the track. */
.SwipeableList-track:focus-visible .SwipeableList-content {
  outline: auto;
  outline-offset: -2px;
}

ধাপ ৩: তালিকার আইটেমে অ্যাকশন আইকন যোগ করুন

অ্যাকশন কালার স্পেসারে (ধাপ ২) থাকে। অ্যাকশন আইকন তালিকা আইটেমে থাকে, যা সারির বাঁ ও ডানদিকের প্রান্তে অ্যাঙ্কর করা থাকে।

নিচে উল্লেখ করা প্লেসমেন্ট, সাইজ ও মোশন হল প্রাথমিক সাজেশন, কোনও আবশ্যকতা নয়। আপনার ডিজাইনের সাথে ম্যাচ করার জন্য আইকনের সাইজ, এজ ইনসেট, থ্রেশহোল্ড-পপ স্কেল, ট্রানজিশনের সময়সীমা এবং এমনকি ছদ্ম-এলিমেন্ট বনাম আসল DOM নোডের মধ্যে থেকে বেছে নিন। একমাত্র মেকানিক্যাল প্রয়োজনীয়তা হল, আইকনটি কন্টেন্টের পিছনে (যাতে কন্টেন্টটি সোয়াইপ করার আগে এটিকে কভার করতে পারে) এবং তালিকা আইটেমের ভিতরে (যাতে এটি স্পেসারের সাথে স্ক্রল না করে) থাকতে হবে। বাকি সব কিছু হল স্বাদ।

/* Action icons painted on the list item. They're absolutely positioned
   inside the row (which is a containing block thanks to `contain: content`
   on `.SwipeableList-item` from Step 2) and sit at z-index 1, so the
   content element (z-index 2) covers them until the user swipes far
   enough. */
.SwipeableList-item.is-initialized::before,
.SwipeableList-item.is-initialized::after {
  /* Inline an SVG as the action icon. Replace this with whatever icon
     fits the action (archive, checkmark, clock, etc.). The `fill='white'`
     is baked into the SVG so it contrasts with the red spacer background;
     adjust if your background color is light. */
  --action-icon: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'><path d='M9 3v1H4v2h1v13a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V6h1V4h-5V3H9zm0 5h2v9H9V8zm4 0h2v9h-2V8z'/></svg>");

  content: '';
  position: absolute;
  z-index: 1;

  /* The size (`width`) and insets (`left`/`right` below) are example
     values, tune them to match your row height and visual weight.
     The icon fills its box via `background-size: contain`, so changing
     `width` resizes it. */
  width: 1.5em; /* example value, adjust to taste */
  aspect-ratio: 1;
  top: 50%;
  translate: 0 -50%;

  /* Smooth transitions for the icon's visual states: the activate-point
     pop (`scale`, see `.is-activating` below) and the removal fade
     (`scale` + `opacity`, see `.is-removing` below). 0.2s is an example
     duration. */
  transition: scale 0.2s ease, opacity 0.2s ease;

  background: var(--action-icon) center / contain no-repeat;
}
/* Inset from the row edge (example values; adjust to match your layout). */
.SwipeableList-item.is-initialized::before { left: 1.5em; }
.SwipeableList-item.is-initialized::after  { right: 1.5em; }

/* Activating pop: scale the icon up when the user is past the visual
   activate point, so the row's affordance feels reactive. Toggled by JS
   in Step 4. */
.SwipeableList-item.is-activating::before,
.SwipeableList-item.is-activating::after {
  scale: 1.333;
}

/* Removal affordance: fade and shrink the icons as the row collapses.
   Driven by the `is-removing` class added in Step 4 at commit time;
   the existing `transition` on the icons animates the change. */
.SwipeableList-item.is-removing::before,
.SwipeableList-item.is-removing::after {
  scale: 0.5;
  opacity: 0;
}

/* Only show the icon on the *leading* side of the swipe; hide the
   trailing-side one. `data-swipe-direction` is set by JS in Step 4. */
.SwipeableList-item.is-activating[data-swipe-direction="left"]::after,
.SwipeableList-item.is-activating[data-swipe-direction="right"]::before {
  visibility: hidden;
}

ধাপ ৪: IntersectionObserver-এর মাধ্যমে কমিট জেসচার শনাক্ত করুন

ট্র্যাকের রুটে IntersectionObserver ব্যবহার করুন, কন্টেন্ট পর্যবেক্ষণ করুন। ব্যবহারকারী সোয়াইপ করার সাথে সাথে, ট্র্যাকের সাথে কন্টেন্টের ইন্টারসেকশন রেশিও কমে যায়; আমরা দুটি থ্রেশহোল্ড ব্যবহার করি:

  • activateThreshold: বেশি অনুপাত (যেমন, ০.৮)। কন্টেন্টের দৃশ্যমান অংশ এর নিচে নেমে গেলে, ব্যবহারকারী ভিজ্যুয়াল অ্যাক্টিভেট পয়েন্ট পেরিয়ে গেছেন বলে ধরা হয়। আইকন-পপ অ্যাফর্ডেন্স টগল করুন।
  • commitThreshold: কম অনুপাত (যেমন, ০.২)। দৃশ্যমান অংশ এর নিচে নেমে গেলে, ব্যবহারকারী কমিট করেছেন। স্ন্যাপ জেসচার সম্পূর্ণভাবে সেটেল হওয়ার জন্য অপেক্ষা না করে, অবিলম্বে সরানোর অ্যানিমেশন শুরু করুন। সারিটি গুটিয়ে যাওয়ার সময় ব্যবহারকারীর সোয়াইপ করার মোমেন্টাম বজায় থাকে, যা স্ন্যাপ ল্যান্ড করার জন্য অপেক্ষা করার চেয়ে বেশি রেসপন্সিভ বলে মনে হয়।

এখানে আরও দুটি সমস্যার সমাধান করা হয়েছে:

  • প্রতিটি আইটেমের জন্য লেজি সেট-আপ: ভিউপোর্টে রুট করা একটিমাত্র বাইরের IntersectionObserver সেট-আপ এবং ভিতরের সোয়াইপ অবজারভারের শুরু/শেষকে ড্রাইভ করে। আইটেমগুলি প্রথমবার স্ক্রল করে ভিউতে আসার পরেই কেবল ওয়্যার আপ করা হয় এবং স্ক্রিনের বাইরে স্ক্রল করা আইটেমগুলির সোয়াইপ অবজারভার পজ করা হয়। এটি অ্যাক্টিভ অবজারভারের সংখ্যা সীমিত রাখে এবং আইটেম রেন্ডার করার আগে লেআউট-নির্ভর ভ্যালু (যেমন clientWidth) রিড করা এড়ায়।
  • ডায়নামিক আইটেম: সময়ের সাথে সাথে আসল তালিকা বড় হয় (প্রাথমিক রেন্ডার, অসীম স্ক্রল, সার্ভার পুশ)। <ul>-এ MutationObserver, বাইরের পর্যবেক্ষকের সাথে নতুন যোগ করা যেকোনও আইটেম রেজিস্টার করে।
// Per-item handles. Populated when an item is first lazily wired up; read by
// the outer viewport observer to start/stop the inner observer as items enter
// and leave the viewport.
const swipeObservers = new WeakMap();

// Outer observer: drives the entire swipe lifecycle off viewport visibility.
// On first entry, lazily wires the item up (`setupItem` reads layout-dependent
// values like `clientWidth`, which return 0 until the item is rendered). After
// setup, starts the inner observer. On exit, stops the inner observer so
// offscreen items don't track scroll positions.
const viewportObserver = new IntersectionObserver((entries) => {
  for (const entry of entries) {
    const item = entry.target;
    if (entry.isIntersecting) {
      const handle = swipeObservers.get(item) ?? setupItem(item);
      handle.observer.observe(handle.content);
    } else {
      const handle = swipeObservers.get(item);
      if (handle) handle.observer.unobserve(handle.content);
    }
  }
});

function setupItem(item) {
  const track = item.querySelector('.SwipeableList-track');
  const content = track.querySelector('.SwipeableList-content');

  // Upgrade the row into "swipeable" mode. This is the gate for all the CSS
  // from Steps 2 and 3 (the track becomes a snap container, the action icons
  // appear). Done *before* the inner observer is attached so the snap
  // container exists by the time intersection callbacks can fire.
  item.classList.add('is-initialized');

  // Tunable thresholds. `activateThreshold` is the visual feedback point
  // (icon pops). `commitThreshold` is the point of no return: once the
  // content is past this point of being off-screen, we commit even if the
  // user releases mid-gesture and the track snaps back. A low value (~0.2)
  // commits before the snap settles, so the remove animation can start
  // during the swipe.
  const activateThreshold = 0.8;
  const commitThreshold = 0.2;

  // One inner observer per item, rooted at the track. Vertical scrolling of
  // the outer list moves root and target together, so the callback only fires
  // for the horizontal swipe.
  const observer = new IntersectionObserver((entries, observer) => {
    const entry = entries.at(-1);
    const ratio = entry.intersectionRatio;

    // Direction the user is swiping toward. A positive offset from the
    // track's left edge means the content has been pulled right (left
    // spacer revealed), so the leading icon is on the left.
    const direction = (entry.boundingClientRect.x - entry.rootBounds.x) > 0
      ? 'left'
      : 'right';

    if (ratio < commitThreshold) {
      // The IO entry's boundingClientRect is the last reliable measurement
      // before the animation starts; reuse it for both the pre-collapse
      // height and the slide-off translate distance.
      removeItem(item, content, direction, entry);
      viewportObserver.unobserve(item);
      observer.disconnect();
      return;
    }

    // Scale up the leading icon while the content is past the activate
    // point; restore it at rest.
    item.classList.toggle('is-activating', ratio < activateThreshold);

    // Hold the previous direction at rest so the icon's exit animation
    // finishes on the side the user was swiping toward.
    if (entry.boundingClientRect.x !== entry.rootBounds.x) {
      item.dataset.swipeDirection = direction;
    }
  }, {
    root: track,
    threshold: [commitThreshold, activateThreshold],
  });

  // Return the handle without starting observation; the outer viewport observer
  // calls `observer.observe(content)` once the item is in view.
  const handle = {observer, content};
  swipeObservers.set(item, handle);
  return handle;
}

async function removeItem(item, content, direction, entry) {
  const opts = { duration: 300, easing: 'ease', fill: 'forwards' };

  const rect = entry.boundingClientRect;
  // Content's pixel offset from the track's left edge.
  const x = rect.x - entry.rootBounds.x;
  // Pixel distance the content needs to travel to be fully out of view.
  const translate = direction === 'left'
    ? rect.width - x
    : -(x + rect.width);

  // Use a combination of CSS transitions (for declarative styles) and
  // WAAPI animations (for computed values) to remove the element,
  // then await the completion of all of them.
  // Note: the content translate animation is important because the
  // height-collapse animation can otherwise finish before the browser's
  // smooth scroll-snap has scrolled the content fully off-screen.
  item.classList.add('is-removing');
  item.animate([{ height: `${rect.height}px` }, { height: '0px' }], opts);
  content.animate([{ translate: `${translate}px` }], opts);
  await Promise.allSettled(
    item.getAnimations({ subtree: true }).map((a) => a.finished),
  );

  // Safari has a scroll-latching bug: removing the node while the swipe
  // gesture's momentum is still resolving causes the next item (which
  // slides up into this one's place) to inherit the scroll and
  // immediately scroll itself off-screen. Detect Safari via
  // `GestureEvent` (a Safari-only API) and defer the actual DOM removal
  // until the gesture has fully settled. The 5s delay is conservative;
  // anything longer than the momentum tail is fine. Mark the row inert
  // so it can't be interacted with during the delay.
  if (globalThis.GestureEvent) {
    item.inert = true;
    setTimeout(() => item.remove(), 5000);
  } else {
    item.remove();
  }
}

function setupList(list) {
  // Observe items already in the list.
  for (const item of list.children) {
    if (item.matches('.SwipeableList-item')) {
      viewportObserver.observe(item);
    }
  }

  // Pick up items added later (initial render after data loads, infinite
  // scroll, server push). Removals don't need MutationObserver handling —
  // the commit branch above already unobserves the item before removing it
  // from the DOM.
  new MutationObserver((mutations) => {
    for (const mutation of mutations) {
      for (const node of mutation.addedNodes) {
        if (node.nodeType === Node.ELEMENT_NODE &&
            node.matches('.SwipeableList-item')) {
          viewportObserver.observe(node);
        }
      }
    }
  }).observe(list, { childList: true });
}

document.querySelectorAll('.SwipeableList').forEach(setupList);

ধাপ ৫: আপনার ব্যবহারের ক্ষেত্রে মানানসই অ্যাকশন ও লেবেল ব্যবহার করুন

সরিয়ে দেওয়া ছাড়া অন্যান্য ভেরিয়েন্টের ক্ষেত্রে, শুধু ভিজ্যুয়াল ও কমিট হ্যান্ডলারের বডি পরিবর্তন হয়:

  • আর্কাইভ: সবুজ/নীল ব্যাকগ্রাউন্ড, আর্কাইভ আইকন, আইটেমটি সরানোর পরিবর্তে আর্কাইভ তালিকায় নিয়ে যান।
  • পড়া হয়েছে হিসেবে চিহ্নিত করুন: ব্যাকগ্রাউন্ডের রঙ হালকা করা, চেকমার্ক আইকন, আইটেমের স্ট্যাটাস আপডেট করা এবং আবার রেন্ডার করা (অথবা শুধু .unread ক্লাস সরিয়ে দেওয়া)।
  • স্নুজ: নীল ব্যাকগ্রাউন্ড, ঘড়ির আইকন, বেছে নেওয়া সময় পর্যন্ত লুকান।

স্ক্রল/স্ন্যাপ/পর্যবেক্ষণ মেকানিক্স অপরিবর্তিত থাকে।

প্রতিটি সোয়াইপ ডিরেকশনের জন্য আলাদা অ্যাকশন

একটি সারি দুটি আলাদা অ্যাকশনও দেখাতে পারে: একটি বাঁদিকে সোয়াইপ করার জন্য এবং একটি ডানদিকে সোয়াইপ করার জন্য (যেমন, ডানদিকে "আর্কাইভ", বাঁদিকে "মুছুন"), যেভাবে অনেক নেটিভ মেল অ্যাপ এটি করে। স্ক্রল, স্ন্যাপ ও কমিট-ডিটেকশন মেকানিক্সে কোনও পরিবর্তন হয় না — শুধু কমিট করার সময় কী হয় তা পরিবর্তন হয়।

ধাপ ৪-এ, কমিট ব্রাঞ্চ সবসময় removeItem(...)-কে কল করে। দুটি অ্যাকশনকে সাপোর্ট করতে, direction-এর উপর ভিত্তি করে হ্যান্ডলার বেছে নিন:

if (ratio < commitThreshold) {
  const handler = direction === 'left' ? archiveItem : removeItem;
  handler(item, content, direction, entry);
  viewportObserver.unobserve(item);
  observer.disconnect();
  return;
}

নামকরণ সম্পর্কে একটি নোট: removeItem-এর নামকরণ করা হয়েছে ডেস্ট্রাক্টিভ কেসের জন্য, কিন্তু এটি যে ফাংশন রান করে (সারির উচ্চতা কমানো, কন্টেন্ট স্লাইড করে স্ক্রিনের বাইরে নিয়ে যাওয়া, তারপর নোড ড্রপ করা) তা আসলে একটি সাধারণ "এই সারির কাজ হয়ে গেছে, অ্যানিমেট করে সরিয়ে দাও" রুটিন। এটি আর্কাইভ, 'পড়া হয়েছে হিসেবে চিহ্নিত করুন' বা স্নুজ করার ক্ষেত্রেও একইভাবে কাজ করে — যেভাবেই হোক, সারিটি এই তালিকা থেকে সরে যায়। আপনার হ্যান্ডলার যদি আসলে কিছু না সরায় (যেমন, দুটিই আইটেমটিকে অন্য কোথাও সরিয়ে দেয়), তাহলে এটিকে dismissItem-এর মতো নিরপেক্ষ কিছুতে রিনেম করুন যাতে কোডটি সঠিকভাবে পড়ে।

দুটি অ্যাকশনকে দৃশ্যত আলাদা করতে, তালিকার আইটেমে প্রতিটি দিকের জন্য একটি রঙ এবং আইকন হোস্ট করুন, তারপরে একই ভেরিয়েবল থেকে একটি স্প্লিট গ্রেডিয়েন্ট এবং দুটি ছদ্ম-এলিমেন্ট আইকন দিয়ে ট্র্যাকটি আঁকুন।

.SwipeableList-item {
  /* Action color + icon per swipe direction. `--left-*` is revealed
     when the user swipes RIGHT (e.g., archive); `--right-*` is revealed
     when the user swipes LEFT (e.g., delete). */
  --left-action-color: hsl(140 50% 40%);
  --left-action-icon: url("…archive svg…");
  --right-action-color: hsl(0 65% 50%);
  --right-action-icon: url("…trash svg…");
}

.SwipeableList-item.is-initialized .SwipeableList-track {
  /* Split reveal: left half of the scrollable area gets the left-action
     color, right half gets the right-action color. `background-attachment:
     local` makes the gradient's positioning area the scrollable area
     (3x the visible width), so the default size fills it and the 50% hard
     stop lines up exactly with the midpoint of the resting content column.
     The track's color also stays continuous behind the content as it
     translates off, so the leading-direction color shows the whole way. */
  background-image: linear-gradient(
    to right,
    var(--left-action-color) 50%,
    var(--right-action-color) 50%
  );
  background-attachment: local;
}

/* Per-side icons read from the same variables. */
.SwipeableList-item.is-initialized::before { background-image: var(--left-action-icon); }
.SwipeableList-item.is-initialized::after  { background-image: var(--right-action-icon); }

এই সেট-আপের মাধ্যমে, স্পেসারদের আর নিজস্ব ব্যাকগ্রাউন্ড-কালার (ট্র্যাকের গ্রেডিয়েন্ট প্রকাশকে ম্যানেজ করে) প্রয়োজন হয় না, তাই আপনি যদি এই ডুয়াল-অ্যাকশন ভেরিয়েন্ট ব্যবহার করেন তাহলে ধাপ ২ থেকে .SwipeableList-track::before, ::after-এ background-color নিয়মটি বাদ দিতে পারেন।

পেশাদার পদ্ধতি ও সমস্যা

  • proximity নয়, mandatory স্ন্যাপ ব্যবহার করুন। proximity-এর মাধ্যমে, সারিটি আংশিকভাবে স্ক্রল করা অবস্থায় থাকতে পারে, যার ফলে অ্যাকশন ব্যাকগ্রাউন্ড অর্ধেক দেখা যায়।
  • ট্র্যাকে overscroll-behavior-x: none সেট করুন। এটি না থাকলে, অতিরিক্ত সোয়াইপ করলে iOS/Android-এ ব্রাউজারের ব্যাক-নেভিগেশন জেসচার ট্রিগার হতে পারে।
  • কন্টেন্ট সম্পূর্ণভাবে অফ-স্ক্রিন হওয়ার জন্য অপেক্ষা না করে, স্ন্যাপ সেটেল হওয়ার আগে থ্রেশহোল্ডে কমিট করুন (যেমন, commitThreshold ≈ 0.2)। এর ফলে জেসচার চলাকালীন সরানোর অ্যানিমেশন শুরু হয়, যা স্ন্যাপ ল্যান্ড করার জন্য অপেক্ষা করার চেয়ে অনেক বেশি রেসপন্সিভ বলে মনে হয়।
  • পৃষ্ঠা লোড হওয়ার সময় প্রতিটি আইটেম ওয়্যারিং করার পরিবর্তে, বাইরের ভিউপোর্ট IntersectionObserver থেকে আইটেম-ভিত্তিক সেট-আপ করুন। এটি আইটেম রেন্ডার করার আগে লেআউট-নির্ভর ভ্যালু (clientWidth ইত্যাদি) পড়া এড়িয়ে যায় এবং ব্যবহারকারী আসলে যা দেখতে পান তার অনুপাতে অ্যাক্টিভ অবজারভারের সংখ্যা বজায় রাখে।
  • আইটেম ডায়নামিকভাবে যোগ করা হলে (ডেটা লোড হওয়ার পরে প্রাথমিক রেন্ডার, অসীম স্ক্রল, সার্ভার পুশ) তালিকায় MutationObserver ব্যবহার করুন। এটি ছাড়া, পৃষ্ঠা লোড হওয়ার পরে যোগ করা আইটেমগুলি ওয়্যার আপ করা যাবে না।
  • ম্যানুয়াল ট্রান্সফর্ম চালানোর জন্য pointerdown/pointermove/pointerup-এর উপর নির্ভর করবেন না। আপনি মোমেন্টাম, স্ন্যাপ-ব্যাক, কীবোর্ড অ্যাক্সেসিবিলিটি এবং রিডিউসড-মোশন হ্যান্ডলিংয়ের সুবিধা হারাবেন যা ব্রাউজার আপনাকে ফ্রিতে দেয়।
  • প্রয়োজন হলে, ধ্বংসাত্মক অ্যাকশন কনফার্ম করুন। "সরিয়ে দিন" বিকল্পের জন্য, সোয়াইপ সম্পূর্ণ হওয়ার পরে একটি পূর্বাবস্থায় ফেরানোর টোস্ট দেখানোর কথা বিবেচনা করুন; জেসচারটি দ্রুত এবং ভুলবশত ট্রিগার করা সহজ।
  • নিশ্চিত করুন যে স্ক্রল ট্র্যাক ফোকাস করা যায়, কীবোর্ড অ্যাক্সেসযোগ্য এবং ভিজ্যুয়াল ফোকাস অ্যাফর্ডেন্স আছে।
  • সোয়াইপ করার মাধ্যমে ট্রিগার করা যেকোনও প্রাসঙ্গিক অ্যাকশনের জন্য অ্যাক্সেসযোগ্য বিকল্প প্রদান করুন (যেমন, দৃশ্যমান বোতাম, প্রাসঙ্গিক মেনু বা এডিট মোড)।

ফলব্যাক স্ট্র্যাটেজি

ব্যবহার করা হয় এমন সব নতুন ফিচার হয় অভিজ্ঞতার মূল অংশ নয় অথবা সেগুলির শক্তিশালী ফলব্যাক আছে যা এখন নির্ভরযোগ্যভাবে ব্যবহার করা যেতে পারে।

overscroll-behavior-এর জন্য ফলব্যাক

এই ব্যবহারের ক্ষেত্রে কোনও ফলব্যাক প্রয়োজন নেই। যদিও overscroll-behavior-এর একটি ইন্টারঅপারেবিলিটি সমস্যা রয়েছে যা স্ক্রোলযোগ্য ওভারফ্লো ছাড়াই কন্টেনারে প্রকাশ পায়, এখানে ট্র্যাকটি সর্বদা অনুভূমিকভাবে স্ক্রোলযোগ্য (১০০% প্রস্থের কন্টেনারের ভিতরে তিনটি পূর্ণ-প্রস্থের কলাম), তাই প্রপার্টিটি ব্রাউজার জুড়ে ধারাবাহিকভাবে আচরণ করে এবং সোয়াইপ জেসচার নির্ভরযোগ্যভাবে থাকে।

scrollbar-width-এর জন্য ফলব্যাক

লুকানো স্ক্রলবার হল একটি ভিজ্যুয়াল উন্নতি, এটি এমন কোনও মেকানিজম নয় যা সোয়াইপ-টু-রিমুভ কাজ করে। আপনার বেসলাইন টার্গেটে scrollbar-width অন্তর্ভুক্ত না থাকলে, সারিটি এখনও স্ক্রল, স্ন্যাপ, কমিট শনাক্ত এবং সঠিকভাবে সরিয়ে দেয়; অসমর্থিত অভিজ্ঞতা কেবল একটি অনুভূমিক স্ক্রলবার দেখাতে পারে। আপনার প্রোডাক্টের জন্য পুরনো WebKit-derived ব্রাউজারে লুকানো স্ক্রলবার প্রয়োজন হলে, আপনি সোয়াইপ ট্র্যাকের জন্য সংকীর্ণভাবে স্কোপ করা ::-webkit-scrollbar { display: none; } নিয়ম যোগ করতে পারেন।

scroll-initial-target-এর জন্য ফলব্যাক

আপনার বেসলাইন টার্গেটে scroll-initial-target অন্তর্ভুক্ত না থাকলে, setupItem-এর মধ্যে প্রোগ্রাম্যাটিক্যালি কন্টেন্টে ট্র্যাক স্ক্রল করুন। CSS.supports-এর মাধ্যমে শনাক্ত করুন:

// Hoist the feature detect so the conditional `ResizeObserver` below can be
// skipped entirely when the property is supported.
const needsScrollWorkaround = !CSS.supports('scroll-initial-target', 'nearest');

function setupItem(item) {
  // ...existing setup from Step 4...

  if (needsScrollWorkaround) {
    track.scrollLeft = track.clientWidth;
  }

  // ...attach the inner IntersectionObserver, etc.
}

কলের ক্রম গুরুত্বপূর্ণ। প্রোগ্র্যামাটিক স্ক্রল অবশ্যই রান করতে হবে:

  1. AFTER .is-initialized তালিকার আইটেমে যোগ করা হয় (ক্লাসটি ট্র্যাককে স্ক্রল কন্টেনারে পরিণত করে; স্ক্রল করা যায় না এমন এলিমেন্টে scrollLeft সেট করলে কোনও কাজ হয় না)।
  2. ধাপ ৪ থেকে ইনার IntersectionObserver অ্যাটাচ করার আগে। অন্যথায়, বাঁদিকের স্পেসারের পরে প্রাথমিক প্রোগ্রাম্যাটিক স্ক্রলকে "সোয়াইপ" হিসেবে দেখা হবে এবং সাথে সাথে কমিট হ্যান্ডলার চালু হয়ে যাবে।

আউটার ভিউপোর্ট অবজারভার (ধাপ ৪) থেকে ড্রাইভিং সেট-আপ এটিকে নির্ভরযোগ্য করে তোলে: আইটেম রেন্ডার করার পরে setupItem রান করে, তাই track.clientWidth, 0-এর পরিবর্তে আসল ভ্যালু রিটার্ন করে।

এছাড়াও, কিছু ব্রাউজার (বিশেষ করে Safari) ট্র্যাকের সাইজ পরিবর্তন (URL-বার দেখানো/লুকানো, ভিউপোর্ট সাইজ পরিবর্তন, কন্টেনার কোয়েরি ইত্যাদি) করার সময় স্ন্যাপ-কন্টেনার স্ক্রল পজিশন রিসেট করে। স্ক্রল আবার প্রয়োগ করতে প্রতিটি ট্র্যাকে ResizeObserver ব্যবহার করুন। একই CSS.supports চেকের পিছনে এটি গেট করুন — scroll-initial-target কাজ করলে, ব্রাউজার নিজেই রিসাইজ-টাইম স্ক্রল রিস্টোরেশন ম্যানেজ করে।

const trackResizeObserver = needsScrollWorkaround
  ? new ResizeObserver((entries) => {
      for (const entry of entries) {
        entry.target.scrollLeft = entry.target.clientWidth;
      }
    })
  : null;

function setupItem(item) {
  // ...existing setup...

  if (needsScrollWorkaround) {
    track.scrollLeft = track.clientWidth;
    trackResizeObserver.observe(track);
  }

  // ...attach the inner IntersectionObserver, etc.
}

removeItem-এ সারির উচ্চতার অ্যানিমেশন রান করার আগে ট্র্যাক আনঅবজার্ভ করুন, অন্যথায় সরানোর সময় উচ্চতার পরিবর্তন রিসাইজ কলব্যাক আবার ট্রিগার করে। কমিট ব্রাঞ্চে আগে থেকে থাকা viewportObserver.unobserve(item)-এর সাথে এটি যোগ করুন:

if (ratio < commitThreshold) {
  removeItem(item, content, direction, entry);
  viewportObserver.unobserve(item);
  if (needsScrollWorkaround) trackResizeObserver.unobserve(track);
  observer.disconnect();
  return;
}