画面の部品を直接指定して修正を頼む

シミュレーターの部品を長押しして修正内容を伝える。対象を文章で説明し直す手間を省いている。

しん · FixKit · 元投稿

長押しした部品に修正メモを結び付ける

元の実例の着眼点を試すための独自のWebサンプルです。

「注文する」を長押しするか、「修正メモを書く」を押し、対象付きで記録してください。

実装の手順

  1. 対象の部品に安定したIDを付け、コメントと一緒に記録する。サンプルではボタンのIDを使う。
  2. 一定時間押し続けたらメモ欄を開く。指を離したときやスクロールで操作が途切れたときはタイマーを解除する。
  3. キーボードや短いタップでも使えるメモ用ボタンを用意する。実アプリではこのUIを開発モードに置く。

動作確認

短いタップでは長押しが発動しない。メモと対象IDを一緒に取得できる。

サンプルコードを見る
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>長押しした部品に修正メモを結び付ける</title>
<style>
  * { box-sizing: border-box; }
  body {
    margin: 0;
    padding: 16px;
    background: #23232a;
    color: #f4f0ea;
    font: 16px/1.6 system-ui, sans-serif;
  }
  label, output, strong, audio, progress { display: block; margin: 6px 0; }
  input, select, button { max-width: 100%; font: inherit; }
  input, select { padding: 4px 7px; }
  button {
    margin: 4px 0;
    padding: 5px 12px;
    cursor: pointer;
    border: 1px solid #b5a399;
    border-radius: 6px;
  }
  :focus-visible { outline: 3px solid #ffad73; outline-offset: 2px; }
  audio { width: 100%; }
  [hidden] { display: none !important; }

</style>
</head>
<body>
<button id="checkout">注文する</button>
<button id="annotate">修正メモを書く</button>
<form id="editor" hidden>
  <label>checkout の修正メモ <input id="comment" required></label>
  <button>メモを記録</button>
</form>
<output id="result"></output>
<script>
const target = document.querySelector('#checkout');
const editor = document.querySelector('#editor');
const comment = document.querySelector('#comment');
function openEditor() { editor.hidden = false; comment.focus(); }
let timer;
function cancel() { clearTimeout(timer); }
target.onpointerdown = event => {
  cancel();
  if (event.isPrimary && event.button === 0) timer = setTimeout(openEditor, 500);
};
for (const type of ['pointerup','pointercancel','pointerleave']) {
  target.addEventListener(type, cancel);
}
document.querySelector('#annotate').onclick = openEditor;
editor.onsubmit = event => {
  event.preventDefault();
  document.querySelector('#result').textContent = target.id + ':' + comment.value;
  editor.hidden = true;
  comment.value = '';
};
</script>
</body>
</html>

index.html に保存し、ブラウザで開くと試せます。

自分の画面で見た目を比較実例一覧