diff --git a/docs/hooks.md b/docs/hooks.md index c613fd62cd..544c1e62e8 100644 --- a/docs/hooks.md +++ b/docs/hooks.md @@ -52,13 +52,13 @@ export default function MyComponent() {
-In React you may need to wrap your component with `forwardRef` to provide direct access to an element (`input` for example). You can do this by using using a `prop` value as the `ref` +In React you may need to wrap your component with `forwardRef` to pass a `ref` property to a component. You can do this by naming one of your Mitosis `prop`s `ref` _Mitosis input_ ```typescript export default function MyInput(props) { - return ; + return ; } ``` @@ -67,8 +67,8 @@ _Mitosis output_ ```typescript import { forwardRef } from 'react'; -export default forwardRef(function MyInput(props, inputRef) { - return ; +export default forwardRef(function MyInput(props, ref) { + return ; }); ``` diff --git a/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap b/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap index 6e9edc2831..dc3082100a 100644 --- a/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap @@ -1443,7 +1443,7 @@ exports[`Alpine.js > jsx > Javascript Test > basicForwardRef 1`] = `
@@ -1710,6 +1710,30 @@ exports[`Alpine.js > jsx > Javascript Test > defaultValsWithTypes 1`] = ` " `; +exports[`Alpine.js > jsx > Javascript Test > dontForwardRef 1`] = ` +" +
+ +
+ +" +`; + exports[`Alpine.js > jsx > Javascript Test > expressionState 1`] = ` "
+" +`; + exports[`Alpine.js > jsx > Typescript Test > expressionState 1`] = ` "
+" +`; + exports[`Html > jsx > Javascript Test > expressionState 1`] = ` "
@@ -9359,7 +9421,7 @@ exports[`Html > jsx > Typescript Test > basicForwardRef 1`] = ` class=\\"input\\" data-el=\\"input-1\\" data-dom-state=\\"input-2\\" - data-ref=\\"undefined-props.inputRef\\" + data-ref=\\"undefined-props.ref\\" />
+ +" +`; + exports[`Html > jsx > Typescript Test > expressionState 1`] = ` "
diff --git a/packages/core/src/__tests__/__snapshots__/liquid.test.ts.snap b/packages/core/src/__tests__/__snapshots__/liquid.test.ts.snap index 11c3f8fbd1..ab51187856 100644 --- a/packages/core/src/__tests__/__snapshots__/liquid.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/liquid.test.ts.snap @@ -584,6 +584,18 @@ exports[`Liquid > jsx > Javascript Test > defaultValsWithTypes 1`] = ` " `; +exports[`Liquid > jsx > Javascript Test > dontForwardRef 1`] = ` +"
+ +
+ +" +`; + exports[`Liquid > jsx > Javascript Test > expressionState 1`] = ` "
{{refToUse}}
" @@ -1446,6 +1458,18 @@ exports[`Liquid > jsx > Typescript Test > defaultValsWithTypes 1`] = ` " `; +exports[`Liquid > jsx > Typescript Test > dontForwardRef 1`] = ` +"
+ +
+ +" +`; + exports[`Liquid > jsx > Typescript Test > expressionState 1`] = ` "
{{refToUse}}
" diff --git a/packages/core/src/__tests__/__snapshots__/lit.test.ts.snap b/packages/core/src/__tests__/__snapshots__/lit.test.ts.snap index b804ebb707..2943ab59b7 100644 --- a/packages/core/src/__tests__/__snapshots__/lit.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/lit.test.ts.snap @@ -2111,10 +2111,10 @@ export default class MyBasicForwardRefComponent extends LitElement { return this; } - @query('[ref=\\"props.inputRef\\"]') - propsInputRef!: HTMLElement; + @query('[ref=\\"props.ref\\"]') + propsRef!: HTMLElement; - @property() inputRef: any; + @property() ref: any; @state() name = \\"PatrickJS\\"; @@ -2125,7 +2125,7 @@ export default class MyBasicForwardRefComponent extends LitElement { }
- + (this.name = event.target.value)} />
@@ -2572,6 +2572,40 @@ export default class ComponentWithTypes extends LitElement { " `; +exports[`Lit > jsx > Javascript Test > dontForwardRef 1`] = ` +"import { LitElement, html, css } from \\"lit\\"; +import { customElement, property, state, query } from \\"lit/decorators.js\\"; + +@customElement(\\"dont-forward-ref-component\\") +export default class DontForwardRefComponent extends LitElement { + createRenderRoot() { + return this; + } + + @query('[ref=\\"props.inputRef\\"]') + propsInputRef!: HTMLElement; + + @property() inputRef: any; + + @state() name = \\"PatrickJS\\"; + + render() { + return html\` + +
+ + (this.name = event.target.value)} /> +
+ + \`; + } +} +" +`; + exports[`Lit > jsx > Javascript Test > expressionState 1`] = ` "import { LitElement, html, css } from \\"lit\\"; import { customElement, property, state, query } from \\"lit/decorators.js\\"; @@ -6330,7 +6364,7 @@ import { customElement, property, state, query } from \\"lit/decorators.js\\"; export interface Props { showInput: boolean; - inputRef: HTMLInputElement; + ref: HTMLInputElement; } @customElement(\\"my-basic-forward-ref-component\\") @@ -6339,10 +6373,10 @@ export default class MyBasicForwardRefComponent extends LitElement { return this; } - @query('[ref=\\"props.inputRef\\"]') - propsInputRef!: HTMLElement; + @query('[ref=\\"props.ref\\"]') + propsRef!: HTMLElement; - @property() inputRef: any; + @property() ref: any; @state() name = \\"PatrickJS\\"; @@ -6353,7 +6387,7 @@ export default class MyBasicForwardRefComponent extends LitElement { }
- + (this.name = event.target.value)} />
@@ -6842,6 +6876,45 @@ export default class ComponentWithTypes extends LitElement { " `; +exports[`Lit > jsx > Typescript Test > dontForwardRef 1`] = ` +"import { LitElement, html, css } from \\"lit\\"; +import { customElement, property, state, query } from \\"lit/decorators.js\\"; + +export interface Props { + showInput: boolean; + inputRef: HTMLInputElement; +} + +@customElement(\\"dont-forward-ref-component\\") +export default class DontForwardRefComponent extends LitElement { + createRenderRoot() { + return this; + } + + @query('[ref=\\"props.inputRef\\"]') + propsInputRef!: HTMLElement; + + @property() inputRef: any; + + @state() name = \\"PatrickJS\\"; + + render() { + return html\` + +
+ + (this.name = event.target.value)} /> +
+ + \`; + } +} +" +`; + exports[`Lit > jsx > Typescript Test > expressionState 1`] = ` "import { LitElement, html, css } from \\"lit\\"; import { customElement, property, state, query } from \\"lit/decorators.js\\"; diff --git a/packages/core/src/__tests__/__snapshots__/marko.test.ts.snap b/packages/core/src/__tests__/__snapshots__/marko.test.ts.snap index c6efae5241..d98d94bc15 100644 --- a/packages/core/src/__tests__/__snapshots__/marko.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/marko.test.ts.snap @@ -1379,20 +1379,20 @@ exports[`Marko > jsx > Javascript Test > basicForwardRef 1`] = ` this.state = { name: \\"PatrickJS\\" }; } - get propsInputRef() { - return this.getEl(\\"propsInputRef\\"); + get propsRef() { + return this.getEl(\\"propsRef\\"); } } style { - .input-7c942903 { + .input-55669c1e { color: red; } }
state.name = event.target.value) /> @@ -1613,6 +1613,32 @@ class {}
Hello \${input.name || DEFAULT_VALUES.name}
" `; +exports[`Marko > jsx > Javascript Test > dontForwardRef 1`] = ` +"class { + onCreate(input) { + this.state = { name: \\"PatrickJS\\" }; + } + + get propsInputRef() { + return this.getEl(\\"propsInputRef\\"); + } +} + +style { + .input-5ca2af3c { + color: red; + } +} +
+ state.name = event.target.value) + /> +
" +`; + exports[`Marko > jsx > Javascript Test > expressionState 1`] = ` "class { onCreate(input) { @@ -3661,20 +3687,20 @@ exports[`Marko > jsx > Typescript Test > basicForwardRef 1`] = ` this.state = { name: \\"PatrickJS\\" }; } - get propsInputRef() { - return this.getEl(\\"propsInputRef\\"); + get propsRef() { + return this.getEl(\\"propsRef\\"); } } style { - .input-014e706f { + .input-421e0008 { color: red; } }
state.name = event.target.value) /> @@ -3897,6 +3923,32 @@ class {}
Hello \${input.name || DEFAULT_VALUES.name}
" `; +exports[`Marko > jsx > Typescript Test > dontForwardRef 1`] = ` +"class { + onCreate(input) { + this.state = { name: \\"PatrickJS\\" }; + } + + get propsInputRef() { + return this.getEl(\\"propsInputRef\\"); + } +} + +style { + .input-30866138 { + color: red; + } +} +
+ state.name = event.target.value) + /> +
" +`; + exports[`Marko > jsx > Typescript Test > expressionState 1`] = ` "class { onCreate(input) { diff --git a/packages/core/src/__tests__/__snapshots__/parse-jsx.test.ts.snap b/packages/core/src/__tests__/__snapshots__/parse-jsx.test.ts.snap index 3fbc2dadea..2c05f4bca3 100644 --- a/packages/core/src/__tests__/__snapshots__/parse-jsx.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/parse-jsx.test.ts.snap @@ -6560,7 +6560,7 @@ exports[`Parse JSX > Javascript > basicForwardRef 1`] = ` "type": "single", }, "ref": { - "code": "props.inputRef", + "code": "props.ref", "type": "single", }, "value": { @@ -8149,6 +8149,97 @@ exports[`Parse JSX > Javascript > defaultValsWithTypes 1`] = ` } `; +exports[`Parse JSX > Javascript > dontForwardRef 1`] = ` +{ + "@type": "@builder.io/mitosis/component", + "children": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [], + "meta": {}, + "name": "div", + "properties": { + "_text": " + ", + }, + "scope": {}, + }, + { + "@type": "@builder.io/mitosis/node", + "bindings": { + "css": { + "code": "{ + color: 'red' +}", + "type": "single", + }, + "onChange": { + "arguments": [ + "event", + ], + "code": "state.name = event.target.value", + "type": "single", + }, + "ref": { + "code": "props.inputRef", + "type": "single", + }, + "value": { + "code": "state.name", + "type": "single", + }, + }, + "children": [], + "meta": {}, + "name": "input", + "properties": {}, + "scope": {}, + }, + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [], + "meta": {}, + "name": "div", + "properties": { + "_text": " + ", + }, + "scope": {}, + }, + ], + "meta": {}, + "name": "div", + "properties": {}, + "scope": {}, + }, + ], + "context": { + "get": {}, + "set": {}, + }, + "exports": {}, + "hooks": {}, + "imports": [], + "inputs": [], + "meta": {}, + "name": "DontForwardRefComponent", + "refs": {}, + "state": { + "name": { + "code": "'PatrickJS'", + "type": "property", + }, + }, + "subComponents": [], +} +`; + exports[`Parse JSX > Javascript > expressionState 1`] = ` { "@type": "@builder.io/mitosis/component", @@ -18608,7 +18699,7 @@ exports[`Parse JSX > Typescript > basicForwardRef 1`] = ` "type": "single", }, "ref": { - "code": "props.inputRef", + "code": "props.ref", "type": "single", }, "value": { @@ -18663,7 +18754,7 @@ exports[`Parse JSX > Typescript > basicForwardRef 1`] = ` "types": [ "export interface Props { showInput: boolean; - inputRef: HTMLInputElement; + ref: HTMLInputElement; }", ], } @@ -20266,6 +20357,104 @@ exports[`Parse JSX > Typescript > defaultValsWithTypes 1`] = ` } `; +exports[`Parse JSX > Typescript > dontForwardRef 1`] = ` +{ + "@type": "@builder.io/mitosis/component", + "children": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [], + "meta": {}, + "name": "div", + "properties": { + "_text": " + ", + }, + "scope": {}, + }, + { + "@type": "@builder.io/mitosis/node", + "bindings": { + "css": { + "code": "{ + color: 'red' +}", + "type": "single", + }, + "onChange": { + "arguments": [ + "event", + ], + "code": "state.name = event.target.value", + "type": "single", + }, + "ref": { + "code": "props.inputRef", + "type": "single", + }, + "value": { + "code": "state.name", + "type": "single", + }, + }, + "children": [], + "meta": {}, + "name": "input", + "properties": {}, + "scope": {}, + }, + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [], + "meta": {}, + "name": "div", + "properties": { + "_text": " + ", + }, + "scope": {}, + }, + ], + "meta": {}, + "name": "div", + "properties": {}, + "scope": {}, + }, + ], + "context": { + "get": {}, + "set": {}, + }, + "exports": {}, + "hooks": {}, + "imports": [], + "inputs": [], + "meta": {}, + "name": "DontForwardRefComponent", + "propsTypeRef": "Props", + "refs": {}, + "state": { + "name": { + "code": "'PatrickJS'", + "type": "property", + }, + }, + "subComponents": [], + "types": [ + "export interface Props { + showInput: boolean; + inputRef: HTMLInputElement; +}", + ], +} +`; + exports[`Parse JSX > Typescript > expressionState 1`] = ` { "@type": "@builder.io/mitosis/component", diff --git a/packages/core/src/__tests__/__snapshots__/preact.test.ts.snap b/packages/core/src/__tests__/__snapshots__/preact.test.ts.snap index cc1dc8fe4b..60a411e2a6 100644 --- a/packages/core/src/__tests__/__snapshots__/preact.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/preact.test.ts.snap @@ -1654,7 +1654,7 @@ function MyBasicForwardRefComponent(props) {
setName(event.target.value)} /> @@ -2071,6 +2071,37 @@ export default ComponentWithTypes; " `; +exports[`Preact > jsx > Javascript Test > dontForwardRef 1`] = ` +"/** @jsx h */ +import { h, Fragment } from \\"preact\\"; +import { useState } from \\"preact/hooks\\"; + +function DontForwardRefComponent(props) { + const [name, setName] = useState(() => \\"PatrickJS\\"); + + return ( + +
+ setName(event.target.value)} + /> +
+ +
+ ); +} + +export default DontForwardRefComponent; +" +`; + exports[`Preact > jsx > Javascript Test > expressionState 1`] = ` "/** @jsx h */ import { h, Fragment } from \\"preact\\"; @@ -5061,7 +5092,7 @@ import { useState } from \\"preact/hooks\\"; export interface Props { showInput: boolean; - inputRef: HTMLInputElement; + ref: HTMLInputElement; } function MyBasicForwardRefComponent(props: Props) { @@ -5072,7 +5103,7 @@ function MyBasicForwardRefComponent(props: Props) {
setName(event.target.value)} /> @@ -5532,6 +5563,42 @@ export default ComponentWithTypes; " `; +exports[`Preact > jsx > Typescript Test > dontForwardRef 1`] = ` +"/** @jsx h */ +import { h, Fragment } from \\"preact\\"; +import { useState } from \\"preact/hooks\\"; + +export interface Props { + showInput: boolean; + inputRef: HTMLInputElement; +} + +function DontForwardRefComponent(props: Props) { + const [name, setName] = useState(() => \\"PatrickJS\\"); + + return ( + +
+ setName(event.target.value)} + /> +
+ +
+ ); +} + +export default DontForwardRefComponent; +" +`; + exports[`Preact > jsx > Typescript Test > expressionState 1`] = ` "/** @jsx h */ import { h, Fragment } from \\"preact\\"; diff --git a/packages/core/src/__tests__/__snapshots__/qwik.test.ts.snap b/packages/core/src/__tests__/__snapshots__/qwik.test.ts.snap index e48d0ac891..41f1696441 100644 --- a/packages/core/src/__tests__/__snapshots__/qwik.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/qwik.test.ts.snap @@ -3463,7 +3463,7 @@ export const MyBasicForwardRefComponent = component$((props) => {
(state.name = event.target.value)} /> @@ -3748,6 +3748,42 @@ export default ComponentWithTypes; " `; +exports[`qwik > jsx > Javascript Test > dontForwardRef 1`] = ` +"import { + Fragment, + component$, + h, + useStore, + useStylesScoped$, +} from \\"@builder.io/qwik\\"; + +export const DontForwardRefComponent = component$((props) => { + useStylesScoped$(STYLES); + + const state = useStore({ name: \\"PatrickJS\\" }); + + return ( +
+ (state.name = event.target.value)} + /> +
+ ); +}); + +export default DontForwardRefComponent; + +export const STYLES = \` +.input-DontForwardRefComponent { + color: red; +} +\`; +" +`; + exports[`qwik > jsx > Javascript Test > expressionState 1`] = ` "import { Fragment, component$, h, useStore } from \\"@builder.io/qwik\\"; @@ -6689,7 +6725,7 @@ exports[`qwik > jsx > Typescript Test > basicForwardRef 1`] = ` export interface Props { showInput: boolean; - inputRef: HTMLInputElement; + ref: HTMLInputElement; } export const MyBasicForwardRefComponent = component$((props: Props) => { useStylesScoped$(STYLES); @@ -6700,7 +6736,7 @@ export const MyBasicForwardRefComponent = component$((props: Props) => {
(state.name = event.target.value)} /> @@ -7014,6 +7050,46 @@ export default ComponentWithTypes; " `; +exports[`qwik > jsx > Typescript Test > dontForwardRef 1`] = ` +"import { + Fragment, + component$, + h, + useStore, + useStylesScoped$, +} from \\"@builder.io/qwik\\"; + +export interface Props { + showInput: boolean; + inputRef: HTMLInputElement; +} +export const DontForwardRefComponent = component$((props: Props) => { + useStylesScoped$(STYLES); + + const state = useStore({ name: \\"PatrickJS\\" }); + + return ( +
+ (state.name = event.target.value)} + /> +
+ ); +}); + +export default DontForwardRefComponent; + +export const STYLES = \` +.input-DontForwardRefComponent { + color: red; +} +\`; +" +`; + exports[`qwik > jsx > Typescript Test > expressionState 1`] = ` "import { Fragment, component$, h, useStore } from \\"@builder.io/qwik\\"; diff --git a/packages/core/src/__tests__/__snapshots__/react-native.test.ts.snap b/packages/core/src/__tests__/__snapshots__/react-native.test.ts.snap index 1927ce89be..5f222167c3 100644 --- a/packages/core/src/__tests__/__snapshots__/react-native.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/react-native.test.ts.snap @@ -1856,13 +1856,13 @@ import { import { useState, forwardRef } from \\"react\\"; const MyBasicForwardRefComponent = forwardRef( - function MyBasicForwardRefComponent(props, inputRef) { + function MyBasicForwardRefComponent(props, ref) { const [name, setName] = useState(() => \\"PatrickJS\\"); return ( setName(event.target.value)} style={styles.view1} @@ -2354,6 +2354,39 @@ export default ComponentWithTypes; " `; +exports[`React Native > jsx > Javascript Test > dontForwardRef 1`] = ` +"import * as React from \\"react\\"; +import { + FlatList, + ScrollView, + View, + StyleSheet, + Image, + Text, +} from \\"react-native\\"; +import { useState } from \\"react\\"; + +function DontForwardRefComponent(props) { + const [name, setName] = useState(() => \\"PatrickJS\\"); + + return ( + + setName(event.target.value)} + style={styles.view1} + /> + + ); +} + +const styles = StyleSheet.create({ view1: { color: \\"red\\" } }); + +export default DontForwardRefComponent; +" +`; + exports[`React Native > jsx > Javascript Test > expressionState 1`] = ` "import * as React from \\"react\\"; import { @@ -5801,17 +5834,17 @@ import { useState, forwardRef } from \\"react\\"; export interface Props { showInput: boolean; - inputRef: HTMLInputElement; + ref: HTMLInputElement; } -const MyBasicForwardRefComponent = forwardRef( - function MyBasicForwardRefComponent(props: Props, inputRef) { +const MyBasicForwardRefComponent = forwardRef( + function MyBasicForwardRefComponent(props: Props, ref) { const [name, setName] = useState(() => \\"PatrickJS\\"); return ( setName(event.target.value)} style={styles.view1} @@ -6346,6 +6379,44 @@ export default ComponentWithTypes; " `; +exports[`React Native > jsx > Typescript Test > dontForwardRef 1`] = ` +"import * as React from \\"react\\"; +import { + FlatList, + ScrollView, + View, + StyleSheet, + Image, + Text, +} from \\"react-native\\"; +import { useState } from \\"react\\"; + +export interface Props { + showInput: boolean; + inputRef: HTMLInputElement; +} + +function DontForwardRefComponent(props: Props) { + const [name, setName] = useState(() => \\"PatrickJS\\"); + + return ( + + setName(event.target.value)} + style={styles.view1} + /> + + ); +} + +const styles = StyleSheet.create({ view1: { color: \\"red\\" } }); + +export default DontForwardRefComponent; +" +`; + exports[`React Native > jsx > Typescript Test > expressionState 1`] = ` "import * as React from \\"react\\"; import { diff --git a/packages/core/src/__tests__/__snapshots__/react.test.ts.snap b/packages/core/src/__tests__/__snapshots__/react.test.ts.snap index ca22df913f..2091203cc3 100644 --- a/packages/core/src/__tests__/__snapshots__/react.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/react.test.ts.snap @@ -1608,7 +1608,7 @@ exports[`React > jsx > Javascript Test > basicForwardRef 1`] = ` import { useState, forwardRef } from \\"react\\"; const MyBasicForwardRefComponent = forwardRef( - function MyBasicForwardRefComponent(props, inputRef) { + function MyBasicForwardRefComponent(props, ref) { const [name, setName] = useState(() => \\"PatrickJS\\"); return ( @@ -1616,7 +1616,7 @@ const MyBasicForwardRefComponent = forwardRef(
setName(event.target.value)} /> @@ -2023,6 +2023,36 @@ export default ComponentWithTypes; " `; +exports[`React > jsx > Javascript Test > dontForwardRef 1`] = ` +"import * as React from \\"react\\"; +import { useState } from \\"react\\"; + +function DontForwardRefComponent(props) { + const [name, setName] = useState(() => \\"PatrickJS\\"); + + return ( + <> +
+ setName(event.target.value)} + /> +
+ + + ); +} + +export default DontForwardRefComponent; +" +`; + exports[`React > jsx > Javascript Test > expressionState 1`] = ` "import * as React from \\"react\\"; import { useState } from \\"react\\"; @@ -4929,11 +4959,11 @@ import { useState, forwardRef } from \\"react\\"; export interface Props { showInput: boolean; - inputRef: HTMLInputElement; + ref: HTMLInputElement; } -const MyBasicForwardRefComponent = forwardRef( - function MyBasicForwardRefComponent(props: Props, inputRef) { +const MyBasicForwardRefComponent = forwardRef( + function MyBasicForwardRefComponent(props: Props, ref) { const [name, setName] = useState(() => \\"PatrickJS\\"); return ( @@ -4941,7 +4971,7 @@ const MyBasicForwardRefComponent = forwardRef(
setName(event.target.value)} /> @@ -5391,6 +5421,41 @@ export default ComponentWithTypes; " `; +exports[`React > jsx > Typescript Test > dontForwardRef 1`] = ` +"import * as React from \\"react\\"; +import { useState } from \\"react\\"; + +export interface Props { + showInput: boolean; + inputRef: HTMLInputElement; +} + +function DontForwardRefComponent(props: Props) { + const [name, setName] = useState(() => \\"PatrickJS\\"); + + return ( + <> +
+ setName(event.target.value)} + /> +
+ + + ); +} + +export default DontForwardRefComponent; +" +`; + exports[`React > jsx > Typescript Test > expressionState 1`] = ` "import * as React from \\"react\\"; import { useState } from \\"react\\"; diff --git a/packages/core/src/__tests__/__snapshots__/rsc.test.ts.snap b/packages/core/src/__tests__/__snapshots__/rsc.test.ts.snap index 2538a280fd..3f56046212 100644 --- a/packages/core/src/__tests__/__snapshots__/rsc.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/rsc.test.ts.snap @@ -1510,6 +1510,7 @@ export default MyBasicForwardRefComponent; exports[`RSC > jsx > Javascript Test > basicForwardRefMetadata 1`] = ` "import * as React from \\"react\\"; +import { forwardRef } from \\"react\\"; const MyBasicForwardRefComponent = forwardRef( function MyBasicForwardRefComponent(props, inputRef) { @@ -1859,6 +1860,30 @@ export default ComponentWithTypes; " `; +exports[`RSC > jsx > Javascript Test > dontForwardRef 1`] = ` +"import * as React from \\"react\\"; + +function DontForwardRefComponent(props) { + const _context = { ...props[\\"_context\\"] }; + + const state = { name: \\"PatrickJS\\" }; + + return ( + <> +
+ +
+ + + ); +} + +export default DontForwardRefComponent; +" +`; + exports[`RSC > jsx > Javascript Test > expressionState 1`] = ` "import * as React from \\"react\\"; @@ -4634,7 +4659,7 @@ exports[`RSC > jsx > Typescript Test > basicForwardRef 1`] = ` export interface Props { showInput: boolean; - inputRef: HTMLInputElement; + ref: HTMLInputElement; } function MyBasicForwardRefComponent(props: Props) { @@ -4645,9 +4670,9 @@ function MyBasicForwardRefComponent(props: Props) { return ( <>
- +
- @@ -4660,13 +4685,14 @@ export default MyBasicForwardRefComponent; exports[`RSC > jsx > Typescript Test > basicForwardRefMetadata 1`] = ` "import * as React from \\"react\\"; +import { forwardRef } from \\"react\\"; export interface Props { showInput: boolean; inputRef: HTMLInputElement; } -const MyBasicForwardRefComponent = forwardRef( +const MyBasicForwardRefComponent = forwardRef( function MyBasicForwardRefComponent(props: Props, inputRef) { const _context = { ...props[\\"_context\\"] }; @@ -5052,6 +5078,35 @@ export default ComponentWithTypes; " `; +exports[`RSC > jsx > Typescript Test > dontForwardRef 1`] = ` +"import * as React from \\"react\\"; + +export interface Props { + showInput: boolean; + inputRef: HTMLInputElement; +} + +function DontForwardRefComponent(props: Props) { + const _context = { ...props[\\"_context\\"] }; + + const state = { name: \\"PatrickJS\\" }; + + return ( + <> +
+ +
+ + + ); +} + +export default DontForwardRefComponent; +" +`; + exports[`RSC > jsx > Typescript Test > expressionState 1`] = ` "import * as React from \\"react\\"; diff --git a/packages/core/src/__tests__/__snapshots__/stencil.test.ts.snap b/packages/core/src/__tests__/__snapshots__/stencil.test.ts.snap index 67ebba0f7c..23a02c4834 100644 --- a/packages/core/src/__tests__/__snapshots__/stencil.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/stencil.test.ts.snap @@ -1765,7 +1765,7 @@ exports[`Stencil > jsx > Javascript Test > basicForwardRef 1`] = ` \`, }) export default class MyBasicForwardRefComponent { - @Prop() inputRef: any; + @Prop() ref: any; @State() name = \\"PatrickJS\\"; @@ -1774,7 +1774,7 @@ export default class MyBasicForwardRefComponent {
(this.props.inputRef = el)} + ref={(el) => (this.props.ref = el)} value={this.name} onInput={(event) => (this.name = event.target.value)} /> @@ -2160,6 +2160,38 @@ export default class ComponentWithTypes { " `; +exports[`Stencil > jsx > Javascript Test > dontForwardRef 1`] = ` +"import { Component, Prop, h, State, Fragment } from \\"@stencil/core\\"; + +@Component({ + tag: \\"dont-forward-ref-component\\", + styles: \` + .input { + color: red; + } +\`, +}) +export default class DontForwardRefComponent { + @Prop() inputRef: any; + + @State() name = \\"PatrickJS\\"; + + render() { + return ( +
+ (this.props.inputRef = el)} + value={this.name} + onInput={(event) => (this.name = event.target.value)} + /> +
+ ); + } +} +" +`; + exports[`Stencil > jsx > Javascript Test > expressionState 1`] = ` "import { Component, Prop, h, State, Fragment } from \\"@stencil/core\\"; @@ -4674,7 +4706,7 @@ exports[`Stencil > jsx > Typescript Test > basicForwardRef 1`] = ` \`, }) export default class MyBasicForwardRefComponent { - @Prop() inputRef: any; + @Prop() ref: any; @State() name = \\"PatrickJS\\"; @@ -4683,7 +4715,7 @@ export default class MyBasicForwardRefComponent {
(this.props.inputRef = el)} + ref={(el) => (this.props.ref = el)} value={this.name} onInput={(event) => (this.name = event.target.value)} /> @@ -5071,6 +5103,38 @@ export default class ComponentWithTypes { " `; +exports[`Stencil > jsx > Typescript Test > dontForwardRef 1`] = ` +"import { Component, Prop, h, State, Fragment } from \\"@stencil/core\\"; + +@Component({ + tag: \\"dont-forward-ref-component\\", + styles: \` + .input { + color: red; + } +\`, +}) +export default class DontForwardRefComponent { + @Prop() inputRef: any; + + @State() name = \\"PatrickJS\\"; + + render() { + return ( +
+ (this.props.inputRef = el)} + value={this.name} + onInput={(event) => (this.name = event.target.value)} + /> +
+ ); + } +} +" +`; + exports[`Stencil > jsx > Typescript Test > expressionState 1`] = ` "import { Component, Prop, h, State, Fragment } from \\"@stencil/core\\"; diff --git a/packages/core/src/__tests__/__snapshots__/svelte.test.ts.snap b/packages/core/src/__tests__/__snapshots__/svelte.test.ts.snap index 96562ee88d..6d9a1826fd 100644 --- a/packages/core/src/__tests__/__snapshots__/svelte.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/svelte.test.ts.snap @@ -1486,13 +1486,13 @@ exports[`Svelte > jsx > Javascript Test > basicForNoTagReference 1`] = ` exports[`Svelte > jsx > Javascript Test > basicForwardRef 1`] = ` "
- +
" +`; + exports[`Svelte > jsx > Javascript Test > expressionState 1`] = ` "
- +
" +`; + exports[`Svelte > jsx > Typescript Test > expressionState 1`] = ` " @@ -1949,6 +1949,32 @@ const props = defineProps([\\"name\\"]); " `; +exports[`Vue > jsx > Javascript Test > dontForwardRef 1`] = ` +" + + + +" +`; + exports[`Vue > jsx > Javascript Test > expressionState 1`] = ` "