Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto close JSX tags. #34307

Closed
arackaf opened this issue Sep 13, 2017 · 23 comments
Closed

Auto close JSX tags. #34307

arackaf opened this issue Sep 13, 2017 · 23 comments
Assignees
Labels
feature-request Request for new features or functionality javascript JavaScript support issues on-testplan typescript Typescript support issues
Milestone

Comments

@arackaf
Copy link

arackaf commented Sep 13, 2017

  • VSCode Version: 1.16.0
  • OS Version: Windows 10

Steps to Reproduce:

  1. Create JSX content, ie <div></div>
  2. Closing </div> does not auto-insert when you close the opening tag

This is a feature request to make the awesome auto-closing-tag feature work with JSX, instead of just html.

@mjbvz mjbvz self-assigned this Sep 13, 2017
@mjbvz mjbvz added feature-request Request for new features or functionality javascript JavaScript support issues typescript Typescript support issues labels Sep 13, 2017
@Igorbek
Copy link

Igorbek commented Sep 28, 2017

I would add that it is desirable that it would work with components as well.

  • Type <C
  • auto-completion shows options where the user selects Component and press tab
  • it is expanded to <Component></Component>

@ghost
Copy link

ghost commented Oct 1, 2017

@Igorbek it doesn't work for me, auto close tags works in HTML, Handlebars, etc., but not in .js file with JSX syntax.

@Igorbek
Copy link

Igorbek commented Oct 1, 2017

It doesn't for me either :) I extended the feature request. That is what I want.

@ghost
Copy link

ghost commented Oct 1, 2017

@Igorbek Oh sorry, I misread your comment 😄

@Igorbek
Copy link

Igorbek commented Oct 1, 2017

no worries, just upvote the feature if you're interested.

@priley86

This comment has been minimized.

@quarleswn
Copy link

quarleswn commented Jan 18, 2018

FYI for anyone else who runs into this: The "auto close tag" extension (https://github.com/formulahendry/vscode-auto-close-tag) implements this and seems to work quite well.

@joshuat
Copy link

joshuat commented Jan 24, 2018

@quarleswn I would avoid that extension, it causes errors with eslint and produces intense CPU spikes. It's likely there's some infinite recursion happening somewhere in there.

It's detailed here: formulahendry/vscode-auto-close-tag#70

@ghost
Copy link

ghost commented Jan 25, 2018

Note that the feature described here: #18427
does a lot of what you're looking for I think.

@PolGuixe
Copy link

Any working solution?

@gor918
Copy link

gor918 commented Mar 24, 2018

@PolGuixe As long as the language mode is "Javascript React", it should work
123

@chuckmasucci
Copy link

It's not working as TypeScript React

@laur1s
Copy link

laur1s commented Apr 13, 2018

Auto tag close not working, this feature is essential.

@bastienGranger
Copy link

bastienGranger commented Apr 18, 2018

+1 it does not work for .tsx files. Auto-closing tags works on html native tags but not on custom and React Native tags

@orszaczky
Copy link

@gor918 Even with "Javascript React" it's not auto-closing the tags

@daphnegold
Copy link

daphnegold commented May 2, 2018

For .jsx files with the mode set to JavaScript React, if I type div and then hit tab then the opening and closing tags are properly generated. If I type <div> the closing tag is not auto-generated. Is this the expected behavior?

One problem is that the Emmet abbreviation is not always the first option in the auto-complete list, for example with the p tag, so it has to be selected manually...

@cmacdonnacha
Copy link

@daphnegold , thanks! I was pulling my hair out trying to figure out why <div> would not generate a closing tag. I then tried just div and it worked. I would suggest that even when using <div> it should still auto close the tag.

mjbvz added a commit that referenced this issue Jun 19, 2018
Part of #34307. Add manual completions for closing jsx tags. Requires TS 3.0
@mjbvz mjbvz modified the milestones: Backlog, July 2018 Jun 27, 2018
@theapache64
Copy link

I've created a small snippet

{
	"Auto close tag": {
		"prefix": "tag",
		"body": [
			"<$1>",
			"</$1>"
		]
	}
}

Type tag and then type your Component name, you'll see the magic. (y)

@mjbvz mjbvz closed this as completed in adfa9ce Jul 10, 2018
@PolGuixe
Copy link

Has it been fixed?

@IllusionMH
Copy link
Contributor

Yep, works for me in VS Code Insider after installing typescript@next as described here

However there is noticeable delay after typing > (in <div>) and when </div> appear, in comparison with simple HTML page or new project created with CRA.
And doesn't close <div> if entered in

<div>
    <div> <- doesn't close here
</div>

@mjbvz should I create separate issue for this delay issue if it depends on project size?

@mjbvz
Copy link
Collaborator

mjbvz commented Jul 10, 2018

Yes this requires TS 3.0+ which is enabled on VS Code insiders. Please open new issues for any problems you see.

@IllusionMH This issue is tracked by microsoft/TypeScript#25552

@ghost
Copy link

ghost commented Aug 5, 2018

Solution is : CTRL + SHIFT + P then type and select "Change Language Mode". Enter javascriptreat

@agavram
Copy link

agavram commented Aug 14, 2018

Adding this to my user settings fixed it for me:

"emmet.includeLanguages": {
    "javascript": "javascriptreact"
},
"emmet.triggerExpansionOnTab": true

@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality javascript JavaScript support issues on-testplan typescript Typescript support issues
Projects
None yet
Development

No branches or pull requests