mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-25 15:42:24 +00:00
[add] 'selectable' prop to Text
This commit is contained in:
@@ -31,4 +31,11 @@ suite('components/Text', () => {
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
test('prop "selectable"', () => {
|
||||
let text = shallow(<Text />)
|
||||
assert.equal(text.prop('style').userSelect, undefined)
|
||||
text = shallow(<Text selectable={false} />)
|
||||
assert.equal(text.prop('style').userSelect, 'none')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -11,18 +11,20 @@ class Text extends Component {
|
||||
|
||||
static propTypes = {
|
||||
accessibilityLabel: createReactDOMComponent.propTypes.accessibilityLabel,
|
||||
accessibilityRole: createReactDOMComponent.propTypes.accessibilityRole,
|
||||
accessibilityRole: PropTypes.oneOf([ 'heading', 'link' ]),
|
||||
accessible: createReactDOMComponent.propTypes.accessible,
|
||||
children: PropTypes.any,
|
||||
numberOfLines: PropTypes.number,
|
||||
onLayout: PropTypes.func,
|
||||
onPress: PropTypes.func,
|
||||
selectable: PropTypes.bool,
|
||||
style: StyleSheetPropType(TextStylePropTypes),
|
||||
testID: createReactDOMComponent.propTypes.testID
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
accessible: true
|
||||
accessible: true,
|
||||
selectable: true
|
||||
};
|
||||
|
||||
render() {
|
||||
@@ -30,6 +32,7 @@ class Text extends Component {
|
||||
numberOfLines,
|
||||
onLayout, // eslint-disable-line
|
||||
onPress, // eslint-disable-line
|
||||
selectable,
|
||||
style,
|
||||
...other
|
||||
} = this.props
|
||||
@@ -41,6 +44,7 @@ class Text extends Component {
|
||||
style: [
|
||||
styles.initial,
|
||||
style,
|
||||
!selectable && styles.notSelectable,
|
||||
numberOfLines === 1 && styles.singleLineStyle
|
||||
]
|
||||
})
|
||||
@@ -63,6 +67,9 @@ const styles = StyleSheet.create({
|
||||
textDecorationLine: 'none',
|
||||
wordWrap: 'break-word'
|
||||
},
|
||||
notSelectable: {
|
||||
userSelect: 'none'
|
||||
},
|
||||
singleLineStyle: {
|
||||
maxWidth: '100%',
|
||||
overflow: 'hidden',
|
||||
|
||||
Reference in New Issue
Block a user