mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-24 15:18:19 +00:00
[fix] nested Text selection
Allow text to be made selectable within a text node that is not selectable. Close #1742
This commit is contained in:
committed by
Nicolas Gallagher
parent
376ccc31b1
commit
12e91a35a4
@@ -25,3 +25,17 @@ exports[`components/Text nested 1`] = `
|
||||
/>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`components/Text prop "selectable" value of false 1`] = `
|
||||
<div
|
||||
class="css-text-901oao r-userSelect-lrvibr"
|
||||
dir="auto"
|
||||
/>
|
||||
`;
|
||||
|
||||
exports[`components/Text prop "selectable" value of true 1`] = `
|
||||
<div
|
||||
class="css-text-901oao r-userSelect-1xnzce8"
|
||||
dir="auto"
|
||||
/>
|
||||
`;
|
||||
|
||||
@@ -21,5 +21,15 @@ describe('components/Text', () => {
|
||||
expect(container.firstChild).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('prop "numberOfLines"', () => {});
|
||||
describe('prop "selectable"', () => {
|
||||
test('value of false', () => {
|
||||
const { container } = render(<Text selectable={false} />);
|
||||
expect(container.firstChild).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('value of true', () => {
|
||||
const { container } = render(<Text selectable={true} />);
|
||||
expect(container.firstChild).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -111,6 +111,7 @@ const Text = forwardRef<TextProps, *>((props, forwardedRef) => {
|
||||
const style = [
|
||||
props.style,
|
||||
numberOfLines != null && numberOfLines > 1 && { WebkitLineClamp: numberOfLines },
|
||||
selectable === true && styles.selectable,
|
||||
selectable === false && styles.notSelectable,
|
||||
onPress && styles.pressable
|
||||
];
|
||||
@@ -207,6 +208,9 @@ const styles = StyleSheet.create({
|
||||
notSelectable: {
|
||||
userSelect: 'none'
|
||||
},
|
||||
selectable: {
|
||||
userSelect: 'text'
|
||||
},
|
||||
pressable: {
|
||||
cursor: 'pointer'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user