Skip to content

Commit a93daa9

Browse files
committed
fix element types with as prop part 1
1 parent be74a9e commit a93daa9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/ui-a11y-content/src/ScreenReaderContent/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,18 @@ class ScreenReaderContent extends Component<ScreenReaderContentProps> {
7272
}
7373

7474
render() {
75-
const { children, styles, ...props } = this.props
76-
const ElementType = getElementType(ScreenReaderContent, props)
75+
const { children, styles, as, ...props } = this.props
76+
// TODO is this ok?
77+
// const ElementType = getElementType(ScreenReaderContent, props)
78+
const Component = as || 'span'
7779
return (
78-
<ElementType
80+
<Component
7981
{...passthroughProps(props)}
8082
css={styles?.screenReaderContent}
8183
ref={this.handleRef}
8284
>
8385
{children}
84-
</ElementType>
86+
</Component>
8587
)
8688
}
8789
}

packages/ui-react-utils/src/getElementType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function getElementType<T extends PropsObject>(
6060
props: T,
6161
getDefault?: () => AsElementType<T>
6262
) {
63-
if (props.as && props.as !== Component.defaultProps?.as) {
63+
if (props.as) {
6464
return props.as
6565
}
6666
if (typeof getDefault === 'function') {
@@ -80,7 +80,7 @@ function getElementType<T extends PropsObject>(
8080
if (typeof props.onClick === 'function') {
8181
return 'button'
8282
}
83-
return Component.defaultProps?.as || 'span'
83+
return 'span'
8484
}
8585

8686
export default getElementType

0 commit comments

Comments
 (0)