ํ์
In iOS Safari, when typing Chinese IME text in table cells (<td>), pressing Space to confirm composition causes both raw Pinyin buffer and confirmed Chinese characters to appear together.
์ฌํ ์์
- Tap on a table cell (
<td>element) to focus. - Activate Chinese IME (iOS Chinese keyboard).
- Type Pinyin โnihaoโ (for Chinese characters โไฝ ๅฅฝโ).
- Press Space to confirm composition.
๊ด์ฐฐ๋ ๋์
- Duplicate text: Pinyin โnihaoโ and Chinese โไฝ ๅฅฝโ appear together โ โnihao ไฝ ๅฅฝโ
- Table cells only: Behavior does not occur in paragraph elements (
<p>,<div>) - iOS Safari specific: Similar to desktop Safari but on mobile devices
- Works in Chrome/Firefox: Other browsers do not exhibit this bug
์์ ๋์
- Pinyin buffer (โnihaoโ) should NOT be visible
- Only confirmed Chinese characters (โไฝ ๅฅฝโ) should appear
์ฐธ๊ณ ์ฌํญ ๋ฐ ๊ฐ๋ฅํ ํด๊ฒฐ ๋ฐฉํฅ
- Use div instead of td: Replace
<td>with<div>for editable content when possible - Force DOM cleanup: Remove Pinyin text after composition completes
- Avoid direct editing in table cells: Use modal or overlay for table cell editing
- Consider non-table structures: Use CSS grid or flexbox instead of HTML tables
์ฝ๋ ์์
const cell = document.querySelector('td[contenteditable]');
let isComposing = false;
cell.addEventListener('compositionstart', () => {
isComposing = true;
});
cell.addEventListener('compositionend', () => {
isComposing = false;
setTimeout(() => {
const text = cell.textContent;
const cleaned = text.replace(/[a-z]+/g, '');
cell.textContent = cleaned;
}, 0);
});
cell.addEventListener('keydown', (e) => {
if (isComposing && e.key === ' ') {
e.preventDefault();
// Let IME complete naturally
}
});