[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:
Richard Lindhout
2020-09-17 23:08:05 +02:00
committed by Nicolas Gallagher
parent 376ccc31b1
commit 12e91a35a4
3 changed files with 29 additions and 1 deletions
@@ -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();
});
});
});
+4
View File
@@ -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'
}