mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-28 16:45:17 +00:00
[add] 'selectable' prop to Text
This commit is contained in:
@@ -32,7 +32,7 @@ Note: Avoid changing `accessibilityRole` values over time or after user
|
|||||||
actions. Generally, accessibility APIs do not provide a means of notifying
|
actions. Generally, accessibility APIs do not provide a means of notifying
|
||||||
assistive technologies of a `role` value change.
|
assistive technologies of a `role` value change.
|
||||||
|
|
||||||
(web) **accessible**: bool = true
|
**accessible**: bool = true
|
||||||
|
|
||||||
When `false`, the text is hidden from assistive technologies. (This is
|
When `false`, the text is hidden from assistive technologies. (This is
|
||||||
implemented using `aria-hidden`.)
|
implemented using `aria-hidden`.)
|
||||||
@@ -54,6 +54,10 @@ height } } }`, where `x` and `y` are the offsets from the parent node.
|
|||||||
|
|
||||||
This function is called on press.
|
This function is called on press.
|
||||||
|
|
||||||
|
**selectable**: bool = true
|
||||||
|
|
||||||
|
Lets the user select the text.
|
||||||
|
|
||||||
**style**: style
|
**style**: style
|
||||||
|
|
||||||
+ ...[View#style](View.md)
|
+ ...[View#style](View.md)
|
||||||
|
|||||||
@@ -31,4 +31,11 @@ suite('components/Text', () => {
|
|||||||
done()
|
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 = {
|
static propTypes = {
|
||||||
accessibilityLabel: createReactDOMComponent.propTypes.accessibilityLabel,
|
accessibilityLabel: createReactDOMComponent.propTypes.accessibilityLabel,
|
||||||
accessibilityRole: createReactDOMComponent.propTypes.accessibilityRole,
|
accessibilityRole: PropTypes.oneOf([ 'heading', 'link' ]),
|
||||||
accessible: createReactDOMComponent.propTypes.accessible,
|
accessible: createReactDOMComponent.propTypes.accessible,
|
||||||
children: PropTypes.any,
|
children: PropTypes.any,
|
||||||
numberOfLines: PropTypes.number,
|
numberOfLines: PropTypes.number,
|
||||||
onLayout: PropTypes.func,
|
onLayout: PropTypes.func,
|
||||||
onPress: PropTypes.func,
|
onPress: PropTypes.func,
|
||||||
|
selectable: PropTypes.bool,
|
||||||
style: StyleSheetPropType(TextStylePropTypes),
|
style: StyleSheetPropType(TextStylePropTypes),
|
||||||
testID: createReactDOMComponent.propTypes.testID
|
testID: createReactDOMComponent.propTypes.testID
|
||||||
};
|
};
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
accessible: true
|
accessible: true,
|
||||||
|
selectable: true
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -30,6 +32,7 @@ class Text extends Component {
|
|||||||
numberOfLines,
|
numberOfLines,
|
||||||
onLayout, // eslint-disable-line
|
onLayout, // eslint-disable-line
|
||||||
onPress, // eslint-disable-line
|
onPress, // eslint-disable-line
|
||||||
|
selectable,
|
||||||
style,
|
style,
|
||||||
...other
|
...other
|
||||||
} = this.props
|
} = this.props
|
||||||
@@ -41,6 +44,7 @@ class Text extends Component {
|
|||||||
style: [
|
style: [
|
||||||
styles.initial,
|
styles.initial,
|
||||||
style,
|
style,
|
||||||
|
!selectable && styles.notSelectable,
|
||||||
numberOfLines === 1 && styles.singleLineStyle
|
numberOfLines === 1 && styles.singleLineStyle
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
@@ -63,6 +67,9 @@ const styles = StyleSheet.create({
|
|||||||
textDecorationLine: 'none',
|
textDecorationLine: 'none',
|
||||||
wordWrap: 'break-word'
|
wordWrap: 'break-word'
|
||||||
},
|
},
|
||||||
|
notSelectable: {
|
||||||
|
userSelect: 'none'
|
||||||
|
},
|
||||||
singleLineStyle: {
|
singleLineStyle: {
|
||||||
maxWidth: '100%',
|
maxWidth: '100%',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
|
|||||||
Reference in New Issue
Block a user