# Three-position Sheet

A bottom sheet settles at three heights over a gallery floor plan.

## Try it

Drag the handle up or down, or choose one of the three height buttons.

## Interaction details

The sheet rests at 30%, 58%, or 90% of the map height and snaps to the nearest stop when released. Escape or a canceled drag restores the starting height. The focused handle supports arrow keys, Home, and End.

## Platform controls

- iOS · Drag the sheet handle up or down to change its height, or tap one of the three height controls.
- Android · Drag the sheet handle up or down to change its height, or tap one of the three height controls.
- PC · Focus the handle and use the up and down arrows, Home, or End. You can also drag the handle.

## Where to use it

Map details, place information, and media controls where the background still matters.

## Implementation prompt

> Snap the sheet to three heights and support drag, buttons, and keyboard controls.

## Sources and credits

[Apple Developer · PresentationDetent](<https://developer.apple.com/documentation/swiftui/presentationdetent>)

## Standalone HTML

Save the code below as an HTML file and open it in your browser. The example works offline.

```html
<!doctype html>
<html lang="en"><head><script>if(new URLSearchParams(location.search).get('reduce')==='1')document.documentElement.classList.add('motion-reduced');</script><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Three-stop Sheet · Motion Lab</title>
<style>
*{box-sizing:border-box}html{color-scheme:light}body{margin:0;font:15px/1.5 system-ui,-apple-system,'Malgun Gothic',sans-serif;word-break:keep-all}main{margin:auto}button{font:inherit;color:inherit;cursor:pointer}button:focus-visible,[tabindex]:focus-visible{outline:3px solid #005bc6;outline-offset:2px}button:disabled{cursor:default}h1,h2,p{margin:0}h1{font-size:clamp(26px,5vw,42px);font-weight:750;letter-spacing:-.075em;line-height:1.2}h2{font-size:18px;letter-spacing:-.04em}.mono{font:600 11px/1.4 ui-monospace,Consolas,monospace;letter-spacing:.055em}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}button{touch-action:manipulation}html.motion-reduced *,html.motion-reduced *::before,html.motion-reduced *::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}}

body{background:#ebe6d8;color:#28281f}main{width:min(100%,700px);padding:clamp(12px,3vw,28px)}.heading{display:flex;align-items:end;justify-content:space-between;border-bottom:1px solid #484c3e;padding:0 0 10px}.heading .mono{margin-bottom:3px;color:#565d4f}.plan{height:clamp(280px,65vh,385px);min-height:280px;position:relative;overflow:hidden;isolation:isolate;background:repeating-linear-gradient(0deg,transparent 0 14px,#78896f24 14px 15px),repeating-linear-gradient(90deg,#c8d0b4 0 14px,#b3c09f 14px 15px);border:1px solid #929d7e;border-top:0}.room{position:absolute;border:3px double #61715a;background:#e9e9d6;display:grid;align-content:center;justify-items:center;font-size:12px;color:#47533f;letter-spacing:.03em}.one{top:9%;left:8%;width:34%;height:24%}.two{top:8%;right:8%;width:39%;height:36%;background:repeating-linear-gradient(135deg,#e9e6c9 0 6px,#d9d6b7 6px 7px)}.three{top:43%;left:8%;width:34%;height:35%}.pin{display:grid;place-items:center;position:absolute;top:30%;left:49%;width:30px;height:30px;border:2px solid #f9f4e0;border-radius:50% 50% 50% 5px;transform:rotate(-45deg);background:#963f29;box-shadow:0 2px 5px #30302535}.pin span{transform:rotate(45deg);font:bold 13px Georgia,serif;color:white}.sheet{position:absolute;inset:auto 6px 0;background:#fbf8eb;box-shadow:0 -3px 18px #35412f32;border-radius:22px 22px 0 0;height:var(--level,30%);display:flex;flex-direction:column;transition:height .28s cubic-bezier(.24,.79,.24,1)}.sheet.drag{transition:none}.grip{min-height:40px;flex:none;display:grid;place-items:center;touch-action:none;cursor:ns-resize;border-radius:22px 22px 0 0}.grip:before{content:"";display:block;width:44px;height:5px;border-radius:5px;background:#707365}.grip:focus-visible{outline-offset:-4px}.content{min-height:0;padding:0 clamp(16px,4vw,30px) 13px;overflow:auto;overscroll-behavior:contain}.roomtitle{font:700 clamp(18px,3.2vw,28px)/1.2 Georgia,system-ui,sans-serif;letter-spacing:-.04em}.sub{font-size:12px;color:#51584b;margin-top:4px}.details{display:grid;grid-template-columns:1fr 1fr;gap:9px 16px;margin:13px 0;border-top:1px solid #c8c8b5;padding-top:10px}.details dt{font-size:11px;color:#59604e}.details dd{margin:2px 0;font-weight:650;font-size:14px}.route{font-size:13px;color:#474f44}.levels{display:flex;margin:10px 0 0;padding:3px;gap:3px;background:#d9dcce;border-radius:6px}.levels button{flex:1;height:44px;border:1px solid transparent;background:none;border-radius:4px;font-weight:650;color:#3c4537}.levels button[aria-pressed=true]{background:#374c3d;color:#fff}.sr{overflow:hidden}@media(max-width:360px){.heading{align-items:start}.heading .mono{font-size:10px}.sheet{inset-inline:3px}.grip{min-height:32px}.content{padding-inline:13px}.details{gap:5px}}

.content:focus-visible{outline-offset:-3px}
</style></head><body>

<main><header class="heading"><div><span class="mono">Gallery plan</span><h1>Letterpress gallery</h1></div><span class="mono">1F</span></header><div class="plan" id="plan"><div class="room one">Paper shelves</div><div class="room two">Print studio</div><div class="room three">Bindery table</div><div aria-hidden="true" class="pin"><span>B</span></div>
<section class="sheet" id="sheet" aria-labelledby="roomtitle"><div role="slider" tabindex="0" aria-label="Visitor information sheet height" aria-orientation="vertical" aria-valuemin="1" aria-valuemax="3" aria-valuenow="1" aria-valuetext="Summary" class="grip" id="grip"></div><div class="content" tabindex="0" role="region" aria-label="Print studio visitor information"><h2 class="roomtitle" id="roomtitle">Gallery B · Print studio</h2><p class="sub">Where type meets paper</p><dl class="details"><div><dt>Location</dt><dd>First floor, east wing</dd></div><div><dt>Next demonstration</dt><dd>2 pm</dd></div><div><dt>Duration</dt><dd>About 20 minutes</dd></div><div><dt>Group size</dt><dd>6 per session</dd></div></dl><p class="route">Pass the paper shelves at the entrance and take the corridor on the right. During demonstrations you can watch the press at work.</p></div></section></div>
<div class="levels" role="group" aria-label="Visitor information sheet height"><button data-level="0" type="button">Summary</button><button data-level="1" type="button">Half</button><button data-level="2" type="button">All</button></div><p class="sr" id="status" role="status"></p></main>

<script>

const plan=document.querySelector('#plan'),sheet=document.querySelector('#sheet'),grip=document.querySelector('#grip'),levels=[.30,.58,.90],names=['Summary','Half','All'];
let active=0,drag=null;
function select(index){active=Math.max(0,Math.min(2,index));sheet.classList.remove('drag');sheet.style.setProperty('--level',levels[active]*100+'%');grip.setAttribute('aria-valuenow',active+1);grip.setAttribute('aria-valuetext',names[active]);for(const button of document.querySelectorAll('[data-level]'))button.setAttribute('aria-pressed',String(Number(button.dataset.level)===active));document.querySelector('#status').textContent='Sheet height · '+names[active];if(active===0)sheet.querySelector('.content').scrollTop=0;}
for(const button of document.querySelectorAll('[data-level]'))button.addEventListener('click',()=>select(Number(button.dataset.level)));
grip.addEventListener('pointerdown',e=>{if(e.button!==0||!e.isPrimary||drag)return;const ratio=sheet.getBoundingClientRect().height/plan.clientHeight;drag={id:e.pointerId,y:e.clientY,start:ratio,value:ratio};sheet.classList.add('drag');grip.setPointerCapture(e.pointerId);});
grip.addEventListener('pointermove',e=>{if(!drag||drag.id!==e.pointerId)return;drag.value=Math.max(levels[0],Math.min(levels[2],drag.start+(drag.y-e.clientY)/plan.clientHeight));sheet.style.setProperty('--level',drag.value*100+'%');});
function end(e,commit){if(!drag||(e&&drag.id!==e.pointerId))return;const d=drag;drag=null;if(grip.hasPointerCapture(d.id))grip.releasePointerCapture(d.id);select(commit?levels.reduce((best,value,i)=>Math.abs(value-d.value)<Math.abs(levels[best]-d.value)?i:best,active):active);}
grip.addEventListener('pointerup',e=>end(e,true));grip.addEventListener('pointercancel',e=>end(e,false));grip.addEventListener('lostpointercapture',e=>end(e,false));
grip.addEventListener('keydown',e=>{const dest={ArrowUp:active+1,ArrowDown:active-1,Home:0,End:2}[e.key];if(dest!==undefined){e.preventDefault();end(null,false);select(dest);}else if(e.key==='Escape'&&drag){e.preventDefault();end(null,false);}});
select(0);

</script></body></html>
```
