المكوّنات · بحث باقتراحات ولوحة مفاتيح
بحث باقتراحات ولوحة مفاتيح
اقتراحات فورية يتنقّل بينها بالأسهم وتُقبل بالإدخال
7 تصاميم من هذه العائلة
<div class="ap apsg"><div class="ph">
<div class="sb"><span class="tm num"></span>
<span class="r" aria-hidden="true"><span>▲</span><span>◗</span><span class="bt num"></span></span></div>
<div class="hdr">
<label class="fld"><span aria-hidden="true">✈</span>
<input type="text" role="combobox" aria-expanded="false" aria-controls="sgl"
aria-autocomplete="list" aria-label="إلى أين؟" placeholder="إلى أين تسافر؟"></label>
<ul id="sgl" class="sg" role="listbox" hidden></ul>
</div>
<div class="body"><div class="pick" hidden></div>
<p class="tip" data-ar="اكتب حرفًا — تنقّل بالأسهم واقبل بالإدخال" data-en="Type a letter — arrow to move, Enter to accept">اكتب حرفًا — تنقّل بالأسهم واقبل بالإدخال</p></div>
<div class="safe"></div>
</div></div>
/* pt-scoped */
/* appsrch-suggest — تطبيق سفر */
.apsg{width:100%;height:100%;display:flex;align-items:center;
justify-content:center;padding:6px;font-size:10px;color:var(--pt-text-secondary);
overflow:hidden}
.apsg .ph{position:relative;width:198px;height:100%;max-height:224px;display:flex;
flex-direction:column;overflow:hidden;background:var(--pt-bg-base);
border:1px solid var(--pt-border-default);border-radius:20px;
box-shadow:var(--pt-shadow-3)}
/* شريط الحالة — ليس تزيينًا: يثبت أعلى الشاشة فلا يبدأ المحتوى عند الحافّة */
.apsg .sb{flex:none;display:flex;align-items:center;justify-content:space-between;
padding:5px 12px 2px;font-size:7px;color:var(--pt-text-muted);
font-variant-numeric:tabular-nums}
.apsg .sb .r{display:flex;gap:3px}
.apsg .scr{flex:1;min-height:0;display:flex;flex-direction:column;overflow:hidden}
.apsg .body{flex:1;min-height:0;overflow-y:auto;overflow-x:hidden;
-webkit-overflow-scrolling:touch}
.apsg .body::-webkit-scrollbar{width:0}
/* المنطقة الآمنة السفلية — شريط الإيماءات يأكل ما تحته */
.apsg .safe{flex:none;height:9px;display:grid;place-items:center}
.apsg .safe::after{content:'';width:52px;height:3px;border-radius:99px;
background:var(--pt-border-strong)}
.apsg h6{margin:0;font-size:10px;color:var(--pt-text-primary);font-weight:600;line-height:1.4}
.apsg p{margin:0;font-size:8px;color:var(--pt-text-muted);line-height:1.65}
.apsg .num{font-variant-numeric:tabular-nums}
.apsg button{font:inherit;cursor:pointer;
transition:background var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
color var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
transform var(--pt-motion-duration-fast) var(--pt-motion-easing-standard)}
.apsg button:focus-visible, .apsg a:focus-visible, .apsg input:focus-visible{
outline:2px solid var(--pt-focus-ring);outline-offset:-1px}
/* هدف اللمس: 44 بكسلًا على الشاشات اللمسية، ومساحة نقر ممتدّة على غيرها */
@media(pointer:coarse){.apsg .tap{min-width:44px;min-height:44px}
}
.apsg .tap{position:relative}
.apsg .tap::before{content:'';position:absolute;inset:-6px}
@media(prefers-reduced-motion:reduce){.apsg *{transition:none!important;animation:none!important}
}
.apsg .hdr{flex:none;position:relative;padding:3px 11px 7px;z-index:3}
.apsg .fld{display:flex;align-items:center;gap:7px;padding:8px 11px;border-radius:99px;
background:var(--pt-bg-inset);border:1px solid var(--pt-border-default);
color:var(--pt-text-muted);font-size:10px}
.apsg .fld:focus-within{border-color:var(--pt-accent)}
.apsg .fld input{flex:1;min-width:0;border:0;background:transparent;font:inherit;
font-size:9.5px;color:var(--pt-text-primary);outline:none}
.apsg .sg{position:absolute;inset-inline:11px;inset-block-start:100%;list-style:none;margin:0;
padding:4px;border-radius:var(--pt-radius-md);background:var(--pt-bg-overlay);
border:1px solid var(--pt-border-default);box-shadow:var(--pt-shadow-4);
max-height:104px;overflow-y:auto}
.apsg .sg li{display:flex;align-items:center;gap:7px;padding:6px 8px;
border-radius:var(--pt-radius-sm);font-size:8.5px;cursor:pointer;color:var(--pt-text-secondary)}
.apsg .sg li[aria-selected=true]{background:var(--pt-accent-muted);color:var(--pt-accent)}
.apsg .sg .cd{font-family:var(--pt-font-mono);font-size:7.5px;color:var(--pt-text-muted);
letter-spacing:.06em}
.apsg .body{padding:9px 12px}
.apsg .pick{padding:9px;border-radius:var(--pt-radius-lg);background:var(--pt-surface);
border:1px solid color-mix(in srgb,var(--pt-accent) 40%,transparent);
display:flex;flex-direction:column;gap:3px}
.apsg .pick b{font-size:11px;color:var(--pt-text-primary)}
.apsg .pick span{font-size:8px;color:var(--pt-text-muted)}
.apsg .pick .pr{font-size:12px;color:var(--pt-accent);font-weight:700;margin-top:3px;
font-variant-numeric:tabular-nums}
.apsg .tip{margin-top:8px;text-align:center}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.apsg');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
var ar = document.documentElement.lang !== 'en';
var n = function (v, d) { return Number(v).toLocaleString('en-US', {
minimumFractionDigits: d || 0, maximumFractionDigits: d || 0 }); };
var money = function (usd, d) {
return ar ? n(usd * 3.75, d) + ' ر.س' : '$' + n(usd, d);
};
var set = function (sel, txt) {
var el = root.querySelector(sel); if (el) el.textContent = txt; return el;
};
/* الساعة بأرقام لاتينية دائمًا — قرار موحّد في المشروع كلّه */
(function clock() {
var t = root.querySelector('.tm');
if (!t) return;
function tick() {
var d = new Date();
t.textContent = String(d.getHours()).padStart(2, '0') + ':' +
String(d.getMinutes()).padStart(2, '0');
setTimeout(tick, 20000);
}
tick();
})();
var bt = root.querySelector('.bt');
if (bt) bt.textContent = '84%';
/* اهتزاز خفيف حيث يوجد — تأكيد لمسيّ لا يعتمد عليه شيء */
var buzz = function (ms) { try { if (navigator.vibrate) navigator.vibrate(ms || 8); } catch (e) {} };
var CITIES = [
{ c: 'الرياض', k: 'RUH', p: 0 }, { c: 'جدّة', k: 'JED', p: 92 },
{ c: 'الدمّام', k: 'DMM', p: 78 }, { c: 'أبها', k: 'AHB', p: 104 },
{ c: 'دبي', k: 'DXB', p: 168 }, { c: 'القاهرة', k: 'CAI', p: 214 },
{ c: 'إسطنبول', k: 'IST', p: 286 }, { c: 'عمّان', k: 'AMM', p: 196 }
];
var input = root.querySelector('input'), sg = root.querySelector('.sg');
var pick = root.querySelector('.pick');
function norm(s) {
return String(s).replace(/[\u064B-\u0652\u0640]/g, '')
.replace(/[\u0622\u0623\u0625]/g, '\u0627').replace(/\u0629/g, '\u0647')
.replace(/\u0649/g, '\u064A').toLowerCase().trim();
}
var found = [], at = -1;
function draw() {
sg.hidden = !found.length;
input.setAttribute('aria-expanded', String(!!found.length));
sg.innerHTML = found.map(function (c, i) {
return '<li id="sgopt' + i + '" role="option" aria-selected="' + (i === at) + '">' +
'<span style="flex:1">' + c.c + '</span><span class="cd">' + c.k + '</span></li>';
}).join('');
/* aria-activedescendant لا نقل التركيز: المؤشّر يبقى في الحقل
بينما يتحرّك الخيار المميَّز، وإلّا انكسرت الكتابة بعد التنقّل. */
if (at >= 0) input.setAttribute('aria-activedescendant', 'sgopt' + at);
else input.removeAttribute('aria-activedescendant');
}
function run() {
var q = norm(input.value);
found = q ? CITIES.filter(function (c) {
return norm(c.c).indexOf(q) === 0 || c.k.toLowerCase().indexOf(q) === 0;
}) : [];
at = found.length ? 0 : -1;
draw();
}
function accept(i) {
var c = found[i]; if (!c) return;
input.value = c.c;
found = []; at = -1; draw();
pick.hidden = false;
pick.innerHTML = '<b>' + c.c + ' · ' + c.k + '</b><span>' +
(ar ? 'ذهاب من الرياض · مباشرة' : 'From Riyadh · direct') + '</span>' +
'<span class="pr">' + money(c.p || 60) + '</span>';
buzz();
}
input.addEventListener('input', run);
input.addEventListener('keydown', function (e) {
if (!found.length) return;
if (e.key === 'ArrowDown') { e.preventDefault(); at = (at + 1) % found.length; draw(); }
if (e.key === 'ArrowUp') { e.preventDefault(); at = (at - 1 + found.length) % found.length; draw(); }
if (e.key === 'Enter') { e.preventDefault(); accept(at); }
if (e.key === 'Escape') { found = []; at = -1; draw(); }
});
sg.addEventListener('click', function (e) {
var li = e.target.closest('li'); if (!li) return;
accept([].indexOf.call(sg.children, li));
});
}
function mount() {
ac = new AbortController();
var real = window.document;
/* وسيط يمرّر كل شيء إلى المستند الحقيقي، ويعلّق كل مستمع بإشارة
تُقطع عند إعادة التركيب — فلا يبقى مستمع من نسخة ماتت. */
var doc = new Proxy(real, {
get: function (t, k) {
if (k === 'addEventListener') {
return function (type, fn, opts) {
var o = (opts && typeof opts === 'object') ? Object.assign({}, opts)
: { capture: !!opts };
o.signal = ac.signal;
return t.addEventListener(type, fn, o);
};
}
var v = t[k];
return typeof v === 'function' ? v.bind(t) : v;
}
});
function track(fn) {
return function (f, ms) { var id = fn(f, ms); timers.push(id); return id; };
}
run(host, doc, track(window.setTimeout.bind(window)),
track(window.setInterval.bind(window)));
}
function unmount() {
if (ac) ac.abort();
// المعرّفان يتشاركان فضاءً واحدًا في المتصفّح، فالإلغاء المزدوج آمن
timers.forEach(function (id) { window.clearTimeout(id); window.clearInterval(id); });
timers = [];
host.innerHTML = snapshot;
}
mount();
addEventListener('pt-lang', function () { unmount(); mount(); });
})();
# Search with Keyboard Suggestions
**Role:** You are an Arabic-first UI designer and front-end engineer. Read the whole
specification before writing a single line, then follow it literally. If two requirements
conflict, favour usability over visual effect.
**Goal:** Search with Keyboard Suggestions — Live suggestions navigable with arrows and accepted with Enter
**Why this component matters:** A combobox needs aria-activedescendant, not focus movement: the caret must stay in the input while the highlighted option changes, or typing after arrowing breaks.
**Direction:** Genuine RTL — not a mirrored Latin layout. Use logical properties
(`margin-inline-start`, `padding-inline`, `inset-inline-start`, `text-align: start`),
never physical ones (`margin-left`, `left`). The layout must flip with `dir` on its own,
with no duplicated rules.
**Typography:** Cairo for Arabic, IBM Plex Sans for Latin. Arabic line-height must be
`0.18` higher than the Latin equivalent — dots, hamzas and maddas need more vertical room.
Arabic font-size runs `1.06×` the Latin size at the same optical weight.
**Numerals:** Western digits in both languages (`1,234.50`). Only the currency changes:
`ر.س` **after** the number in Arabic, `$` **before** it in English. Jordanian dinar
uses **three** decimal places, not two.
**Colors:** Dark mode — background `#0D142B` · surfaces `#211F54` · borders `#545C91` · text `#918FC2`.
Accent `#ADA9E8` must never exceed 8% of the screen area.
**Language:** Bilingual — every string carries both Arabic and English, and the layout
flips with `dir` automatically.
**States:** `default` · `hover` · `focus` · `active` · `disabled` · `loading` · `error`.
Do not design the resting state alone.
**Accessibility:** Contrast ratio at least `4.5:1`, complete keyboard navigation,
visible focus rings, and honour `prefers-reduced-motion`.
**Output:** Clean HTML and CSS in two separate files. No frameworks, no libraries,
no external dependencies.