First-class (partial) text selection support on mobile (iOS) for `<html.p />`, `<html.h1 />`, `<html.span />`, et al
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- javascript, react-native
调研方向
从 createStrictDOMTextComponent 入口点开始,并将其与 createStrictDOMTextInputComponent 进行比较,然后复现 issue 中的最小 Expo/iOS 示例。跟踪原生 HTML 文本元素如何映射到 React Native 组件,并评估针对 selectable 提议的 opt-in 结构。完成后应在不改变默认行为或 Web 行为的情况下,提供部分原生 iOS 文本选择功能。
由索引模型根据 Issue 内容生成。
描述
Describe the feature request
On iOS (only mobile platform I've tested so far), let text-bearing html.* elements:
html.phtml.h1...html.h6html.lihtml.spanhtml.code- et al
...participate in the native partial-text-selection affordance:
- drag to extend a range
- selection handles
- magnifier
- ...and the system edit menu; i.e.:
- Copy
- Look Up
- Translate
- Share
- Speak
- Writing Tools
Same behaviour React Native for (Desktop) macOS already provides via react-native-macos's NSTextView (and that browsers provide on web).
iOS is the outlier.
Android: yet to be tested. (OpenHarmony, likely entirely out of scope).
Current behaviour
Setting userSelect: 'text' on a text-bearing html.* element on iOS surfaces the iOS edit menu on long-press, but only with Copy. There is no selection range: the menu opens directly, dragging does nothing, no magnifier, no handles. Tapping Copy copies the whole element's text rather than a chosen range.
Minimal reproduction (Expo SDK 55 + [email protected], iOS 16+):
import { html, css } from 'react-strict-dom';
const styles = css.create({
p: { fontSize: 16, lineHeight: 1.45, userSelect: 'text' },
});
export default function Demo() {
return (
<html.p style={styles.p}>
Long-press this paragraph on iOS. The system edit menu opens
immediately with only `Copy`. No selection handles, no
drag-to-extend, no magnifier. The same `html.p` on macOS
supports full partial selection.
</html.p>
);
}
Why it matters
The asymmetry breaks consistent UX across the platforms RSD targets:
| Platform | Partial selection | System edit menu |
|---|---|---|
| Web | ✅ browser default | ✅ browser default |
macOS (react-native-macos) |
✅ NSTextView default |
✅ AppKit default |
iOS (react-native) |
❌ | Copy only |
Android (react-native) |
❌ | ([likely] out of scope here) |
For any reader-oriented surface (articles, chat messages, notes, markdown viewers, quoted replies) partial selection is table stakes. Users who experience macOS and iOS in the same app are particularly badly served by the gap.
Root cause
html.p / html.h1 ... html.h6 / html.li / html.span / html.code all map to react-native's Text on native (createStrictDOMTextComponent → Text). React Native's iOS Text is RCTParagraphComponentView (Fabric) / RCTTextView (legacy): a custom UIView that draws via NSLayoutManager. It doesn't implement UITextInteraction, so iOS has nothing to attach selection handles to.
The well-known RN-iOS workaround for partial-text selection is <TextInput editable={false} multiline selectable />, backed by UITextView and inheriting full selection + native edit menu. RSD already maps html.input and html.textarea to TextInput via createStrictDOMTextInputComponent: the primitive is right there; it just isn't what static text elements compile to.
Proposed shapes (sketches, in increasing invasiveness)
-
New
selectableHTML prop, opt-in: RSD adds aselectableboolean prop to text elements; when true on iOS, the underlying renderer wraps the content in a read-onlyTextInput. Default false; web semantics unchanged.<html.p selectable>…</html.p> -
Render-mode escape hatch: a new prop or variant that lets a consumer opt into TextInput-backed rendering for paragraphs / headings they want fully selectable. More general than a single boolean
-
Map
userSelect: 'text'(or other) toTextInput-readonly on iOS automatically: most magical, most spooky-action-at-a-distance; possibly breaks consumers relying onText-specific layout behaviour thatTextInput-readonly approximates rather than matches
"1" seems like the cleanest first cut: opt-in, doesn't change defaults, matches the platform reality that "selectable static text on iOS" is a distinct rendering choice rather than a free property of Text.
Workarounds (naive assumptions...)
<TextInput editable={false} multiline selectable />used directly (canonical RN-iOS pattern, but bypasses RSD's semantic mapping)react-native-selectable-text: community library wrapping the above- Conditional renderers that swap RSD primitives for RN's
TextInputon iOS: works but pushes platform-divergence into consumer code
All of these work, but each lives outside RSD's surface. The gap is a consistent, RSD-supported way to mark static text as selectable that handles the platform divergence so consumers don't have to.
Related / "Prior Art"
- React Native issue #23147 (closed): original observation that selection ranges aren't exposed on
Text; the RN team's answer was effectively "useTextInputread-only," which is the right RSD-side answer if you accept that rendering choice - RSD's recent input-side
setSelectionRange/selectionStart/selectionEndpolyfill work (commit65e439b, Dec 2025) shows selection is on the roadmap on the input side; static-text selection is the natural companion
(Likely) Out of scope
- Editor/ cursor/keyboard navigation (these need
editable-true paths and are larger) - Android partial selection (related, but RN-Android has its own constraints; deserves a separate issue)
- Selection-event callbacks (
onSelectionChangeon static text): useful, but layerable on top of basic selection support
- 主要语言
- JavaScript
- 星标
- 3.6k
- 派生
- 208
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
react/react-strict-dom 的其他 Issue
-
Outline styles aren't parsed in React Native可能已有人在做 @hoangvvo 于 149 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 65/100
react/react-strict-dom#467 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
react/react-strict-dom#465 · 2 条评论 ·
-
postcss plugin re-transforms every included file on each rebuild under Turbopack (minutes-long HMR in large projects)可能已有人在做 @borisyankov 于 18 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 35/100
react/react-strict-dom#520 ·
-
bug
难度 2/5 1-3 小时 新手友好度 35/100
react/react-strict-dom#505 · 2 个 reaction ·
-
Button remains unclickable after disabled state changes可能已有人在做 @MoOx 于 132 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 62/100
react/react-strict-dom#491 · 4 条评论 ·
查看 react/react-strict-dom 的全部 Issue
相似的 Issue
-
Harden bayesian-waves-bg.js: add prefers-reduced-motion, pointer-events guard, and hidden-tab pause未关闭
难度 2/5 1-3 小时 新手友好度 85/100
-
难度 1/5 1 小时以内 新手友好度 90/100
njitacm/njit-acm-website#109 ·
-
type: bug
难度 2/5 1-3 小时 新手友好度 76/100
blamechris/chroxy#8579 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
modusensus/dsh-mneme#411 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复