Skip to content

Commit

Permalink
[fix] nested Text selection
Browse files Browse the repository at this point in the history
Allow text to be made selectable within a text node that is not selectable.

Close #1742
  • Loading branch information
RichardLindhout authored and necolas committed Sep 21, 2020
1 parent 376ccc3 commit 12e91a3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 4 additions & 0 deletions packages/react-native-web/src/exports/Text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
Expand Down Expand Up @@ -207,6 +208,9 @@ const styles = StyleSheet.create({
notSelectable: {
userSelect: 'none'
},
selectable: {
userSelect: 'text'
},
pressable: {
cursor: 'pointer'
}
Expand Down

0 comments on commit 12e91a3

Please sign in to comment.