From f4a3951ef6cbb9af41dfdf8785329b1f26df58ad Mon Sep 17 00:00:00 2001 From: Joakim Bjerknes Date: Thu, 30 Nov 2023 12:20:53 +0100 Subject: [PATCH] add test for Textarea --- .../src/components/textarea/Textarea.js | 8 ++++- .../textarea/__tests__/Textarea.test.tsx | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/dnb-eufemia/src/components/textarea/Textarea.js b/packages/dnb-eufemia/src/components/textarea/Textarea.js index 7c6f29f4d07..9b7a42957f1 100644 --- a/packages/dnb-eufemia/src/components/textarea/Textarea.js +++ b/packages/dnb-eufemia/src/components/textarea/Textarea.js @@ -195,7 +195,7 @@ export default class Textarea extends React.PureComponent { constructor(props) { super(props) - this._ref = props.inner_ref || React.createRef() + this._ref = React.createRef() this._id = props.id || makeUniqueId() // cause we need an id anyway // make sure we don't trigger getDerivedStateFromProps on startup @@ -206,6 +206,12 @@ export default class Textarea extends React.PureComponent { this.state._value = props.value } componentDidMount() { + if (this.props.inner_ref) { + typeof this.props.inner_ref === 'function' + ? this.props.inner_ref(this._ref.current) + : (this.props.inner_ref.current = this._ref.current) + } + if (isTrue(this.props.autoresize) && typeof window !== 'undefined') { this.setAutosize() try { diff --git a/packages/dnb-eufemia/src/components/textarea/__tests__/Textarea.test.tsx b/packages/dnb-eufemia/src/components/textarea/__tests__/Textarea.test.tsx index 511c59c2dde..0b1956c9584 100644 --- a/packages/dnb-eufemia/src/components/textarea/__tests__/Textarea.test.tsx +++ b/packages/dnb-eufemia/src/components/textarea/__tests__/Textarea.test.tsx @@ -265,6 +265,37 @@ describe('Textarea component', () => { expect(await axeComponent(Comp)).toHaveNoViolations() }) + + it('gets valid ref element', () => { + let ref: React.RefObject + + function MockComponent() { + ref = React.useRef() + return