モバイルUX改善の実装パターン — タップターゲット・2段階操作・メタデータ自動取得
PWAのモバイル対応において、PC向けUIをそのまま流用すると操作性が大幅に低下する。本記事では、ブックマーク管理アプリで実施した3つのUX改善について、実装コードとともに解説する。
課題: PC向けUIのモバイル問題
PC向けに設計したUIをスマホで操作した際に、以下の問題が発生した。
- ボタンが小さくタップしにくい(誤タップ頻発)
- 編集・削除・リンク表示が密集している
- URL入力後、タイトル等を手動入力する必要がある
改善1: タップターゲットの最適化
Apple Human Interface Guidelinesでは最小44x44pt、Material Designでは48x48dpが推奨されている。
/* モバイル用ボタンサイズ */
@media (max-width: 768px) {
.action-button {
min-width: 44px;
min-height: 44px;
padding: 12px;
/* タップ領域を視覚的なボタンより広くする */
position: relative;
}
.action-button::before {
content: '';
position: absolute;
top: -8px;
right: -8px;
bottom: -8px;
left: -8px;
}
}
::before 疑似要素でタップ領域を視覚サイズより広げることで、見た目を変えずにタップしやすくする。
改善2: 2段階タップパターン
リスト項目に複数のアクション(開く・編集・削除)がある場合、ワンタップですべてのボタンを表示すると誤操作が発生する。2段階タップで解決した。
class BookmarkItem {
constructor(element) {
this.element = element;
this.isExpanded = false;
this.element.addEventListener('click', (e) => this.handleTap(e));
}
handleTap(e) {
// アクションボタン自体がタップされた場合はそのまま実行
if (e.target.closest('.action-button')) return;
if (!this.isExpanded) {
// 1回目: アクションボタンを表示
this.expand();
} else {
// 2回目: リンクを開く
window.open(this.element.dataset.url, '_blank');
}
}
expand() {
// 他のアイテムを閉じる
document.querySelectorAll('.bookmark-item.expanded')
.forEach(item => item.classList.remove('expanded'));
this.element.classList.add('expanded');
this.isExpanded = true;
}
}
.bookmark-item .actions {
display: none;
gap: 8px;
}
.bookmark-item.expanded .actions {
display: flex;
animation: slideIn 0.2s ease-out;
}
@keyframes slideIn {
from { opacity: 0; transform: translateY(-4px); }
to { opacity: 1; transform: translateY(0); }
}
他のアイテムをタップすると、展開中のアイテムが自動的に閉じる。これにより画面が散らからない。
改善3: URL貼り付け時のメタデータ自動取得
URLを入力するだけでタイトル・説明文を自動取得する機能を実装した。
async function fetchMetadata(url) {
try {
// CORSプロキシ経由でHTMLを取得
const response = await fetch(
`https://api.allorigins.win/raw?url=${encodeURIComponent(url)}`
);
const html = await response.text();
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
return {
title: getMetaContent(doc, 'og:title')
|| doc.querySelector('title')?.textContent || '',
description: getMetaContent(doc, 'og:description')
|| getMetaContent(doc, 'description') || '',
image: getMetaContent(doc, 'og:image') || ''
};
} catch (error) {
console.warn('メタデータ取得に失敗:', error);
return null;
}
}
function getMetaContent(doc, property) {
const meta = doc.querySelector(
`meta[property="${property}"], meta[name="${property}"]`
);
return meta?.getAttribute('content') || '';
}
Open Graphタグを優先し、フォールバックとして通常のmetaタグ・titleタグを参照する。CORSの制約があるため、プロキシサービス経由で取得している。
Firestoreの1MB制限対策
ドキュメントサイズが1MBを超えると書き込みが失敗する。メタデータ取得で画像URLは保持するが、Base64画像データはクラウドに送らない設計とした。
function prepareForSync(collections) {
return collections.map(col => ({
name: col.name,
items: col.items.map(item => ({
url: item.url,
title: item.title,
description: item.description,
favicon: item.favicon,
createdAt: item.createdAt,
// 除外: image (Base64), articleContent (HTML全文)
}))
}));
}
ローカルストレージにはフルデータを保持し、同期時にクラウドデータとローカルデータをマージする。
まとめ
モバイルUX改善は「使ってみて問題を見つけ、修正する」のサイクルが最も効果的である。タップターゲットの拡大・2段階操作・自動入力の3施策で、モバイルでの操作ミスが大幅に減少した。
この記事は、開発の記録をもとに Claude Code が下書きし、私が確認して公開しています。