scroll-into-view
Scrolls an element into view — on connect by default, or on click / any event via the inherited listen-for.
Features
- Scroll on connect Works with no attributes needed
- Any trigger Combine with
listen-forto scroll on click, custom events, or lifecycles - Alignment control
scroll-alignpicks start / center / end / nearest per axis - Offset for fixed headers
scroll-offsetnudges the final position after alignment - Skip redundant scrolls
if-neededscrolls only when the target isn't already visible
Installation
This package is available in the
<script src="https://unpkg.com/@excom/kit-utils@0.3.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/neutron@0.2.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/scroll-into-view@0.1.4/dist/index.umd.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@excom/scroll-into-view@0.1.4/dist/index.css">npm install @excom/scroll-into-view<!-- import path to `node_modules` will depend on your build setup -->
<script type="module" src="/node_modules/@excom/scroll-into-view"></script>
<link rel="stylesheet" href="/node_modules/@excom/scroll-into-view">import "@excom/scroll-into-view";@import "@excom/scroll-into-view/index.css";Peer dependencies (0)
Packages a consumer must install alongside this one. Workspace deps are bundled.
| Package | Version |
|---|---|
|
Usage
By default, <scroll-into-view> scrolls itself into view as soon as it connects to the DOM. Set target-ref to scroll a different element instead, and pair with the inherited listen-for to trigger on click or any event rather than on connect.
<!-- Jump to a section on click -->
<scroll-into-view target-ref="#pricing" listen-for="click">
See pricing
</scroll-into-view><!-- Jump to a section on click -->
<scroll-into-view target-ref="#pricing" listen-for="click">
See pricing
</scroll-into-view>API Reference
Attributes
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
Provision
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
Events
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements
Child or descendant elements are recognized by and relevant to its functionality.Styles
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
scroll-into-view
Attributes (18)
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
delay-ms
delayMs
number
nullhost-ref
window / document — e.g. Escape to dismiss a dialog from a global keydown. Defaults to :scope. Used with listen-for. Not compatible with listen-for-lifecycle. The selector MUST resolve when host-ref is set — it will not wait for a match to appear.
hostRef
string
<CSS Selector> | "window" | "document" | "html" | "body" | "head"nullif-needed
ifNeeded
boolean
falseis-debounced
delay-ms, coalesce bursts into one trailing call (debounce).
isDebounced
boolean
falsekeycode-filter
+ (AND, any order): shift+k tab → Shift+K or Tab. Modifiers: shift, alt, ctrl/control, meta/cmd. Name the space bar space / spacebar and the plus key plus (shift+space). Case-insensitive.
keycodeFilter
tokenlist
<key | mod+key>…nulllisten-for
click when unset (and no lifecycle list is set).
listenFor
tokenlist
<EventName>…nulllisten-for-lifecycle
listenForLifecycle
tokenlist
"connected" | "disconnected" | "adopted"nulllisten-once
listenOnce
boolean
falsepathname-filter
location.pathname is one of these values — route-aware behaviors without a separate router element.
pathnameFilter
tokenlist
<pathname>…nullprevent-default
preventDefault() on matched events (ignored for lifecycles).
preventDefault
boolean
falsescroll-align
<inline> <block> (x and y, respectively) controlling how the target aligns inside the scrollport. Each token is start, center, end, nearest, or none (skip alignment on that axis).
scrollAlign
tokenlist
"start" | "center" | "end" | "nearest" | "none""nearest start"scroll-behavior
scrollBehavior
string
"auto" | "smooth" | "instant""auto"scroll-offset
<x> <y> applied after alignment — e.g. leave room for a sticky header by using a negative <y>.
scrollOffset
tokenlist
<px> <px>"0 0"selector-filter
event.target matches this CSS selector. Does not support :scope in the selector.
selectorFilter
string
<CSS Selector>nullstop-immediate-propagation
stopImmediatePropagation() on matched events (ignored for lifecycles).
stopImmediatePropagation
boolean
falsestop-propagation
stopPropagation() on matched events (ignored for lifecycles).
stopPropagation
boolean
falsetarget-ref
targetRef
string
<CSS Selector>nullvibrate-ms
navigator.vibrate). Empty / 0 uses a 20ms pulse.
vibrateMs
number
"20 (when attribute is present with no value)"Provision (0)
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
Events (0)
e.preventDefault() is not
synchronously called on the event.
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements (0)
Child or descendant elements are recognized by scroll-into-view and relevant to its functionality.Styles (1)
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
:--scroll-into-viewscroll-into-view, .tag-scroll-into-viewRelease notes (1)
0.1.1
- Ship only dist (and declared extras) in the npm tarball; drop build logs, tests and sources
Release notes
e.preventDefault() is not
synchronously called on the event.
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
Examples
Offset for a sticky header
scroll-offset="0 -50" (negative <y>) leaves room for a sticky header after alignment; scroll-behavior="smooth" animates the scroll. This is the pattern used to jump between sections without the header covering the target's heading.