Skip to content

Commit 78f3b82

Browse files
committed
feat: ref methods
1 parent f7933e9 commit 78f3b82

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

docs/WEB.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ See [Web Keyboard Shortcuts](./INPUT_API_REFERENCE.md#web-keyboard-shortcuts) fo
3838
### What works
3939

4040
- Customizing the styling using props: `style`, `htmlStyle`, `selectionColor`.
41+
- `selectable` prop
42+
- `useHtmlNormalizer`
4143

4244
### Unsupported
4345

44-
- **`selectable`**: ignored on web.
45-
- **`useHtmlNormalizer`**: ignored on web.
4646
- **`ellipsizeMode`**: ignored on web.
4747
- **`numberOfLines`**: ignored on web.
4848
- **Press events**: `onLinkPress` and `onMentionPress` callbacks are ignored on web.
49+
- **RN layout ref methods**: `measure`, `measureInWindow`, `measureLayout`, and `setNativeProps` are no-ops.
4950

5051
## HTML sanitization
5152

src/web/EnrichedText.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { memo, useMemo, useRef, type CSSProperties } from 'react';
1+
import {
2+
memo,
3+
useImperativeHandle,
4+
useMemo,
5+
useRef,
6+
type CSSProperties,
7+
} from 'react';
28
import type { EnrichedTextProps } from '../types';
39
import './EnrichedText.css';
410
import { enrichedTextStyleToCSSProperties } from './styleConversion/enrichedTextStyleToCSSProperties';
@@ -17,6 +23,7 @@ import { usePressInteractions } from './usePressInteractions';
1723

1824
export const EnrichedText = memo(
1925
({
26+
ref,
2027
children,
2128
htmlStyle,
2229
style,
@@ -26,6 +33,19 @@ export const EnrichedText = memo(
2633
}: EnrichedTextProps) => {
2734
const containerRef = useRef<HTMLDivElement>(null);
2835

36+
useImperativeHandle(ref, () => ({
37+
measureInWindow: () => {},
38+
measure: () => {},
39+
measureLayout: () => {},
40+
setNativeProps: () => {},
41+
focus: () => {
42+
containerRef.current?.focus();
43+
},
44+
blur: () => {
45+
containerRef.current?.blur();
46+
},
47+
}));
48+
2949
const sanitizedHtml = useMemo(() => sanitizeHtml(children), [children]);
3050

3151
const finalHtml = useMemo(
@@ -79,6 +99,7 @@ export const EnrichedText = memo(
7999
{mentionRulesCSS ? <style>{mentionRulesCSS}</style> : null}
80100
<div
81101
ref={containerRef}
102+
tabIndex={-1}
82103
style={finalStyle}
83104
className={ENRICHED_TEXT_CLASSNAME}
84105
dangerouslySetInnerHTML={{ __html: finalHtml }}

0 commit comments

Comments
 (0)