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

Suggestions for jsx attributes should include ="" #38891

Closed
yunti opened this issue May 20, 2020 · 11 comments
Closed

Suggestions for jsx attributes should include ="" #38891

yunti opened this issue May 20, 2020 · 11 comments
Assignees
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Rescheduled This issue was previously scheduled to an earlier milestone Suggestion An idea for TypeScript

Comments

@yunti
Copy link

yunti commented May 20, 2020

TS Template added by @mjbvz

TypeScript Version: 3.9.4

Search Terms

  • suggest, suggestion, completions
  • snippet
  • react, jsx

In vscode the autocomplete for className just adds className in webstorm it adds className="" is there a way in vscode to get it to add the additional =""?

I'm not sure currently where the autocomplete comes from, whether it is inbuilt into vscode or comes from the React plugin I use (although it doesn't appear to be in their snippets).

https://github.com/dsznajder/vscode-es7-javascript-react-snippets

@mjbvz mjbvz transferred this issue from microsoft/vscode Jun 2, 2020
@mjbvz mjbvz changed the title REact autocomplete for className misses ="" like webstorm Suggestions for jsx attributes should include ="" Jun 2, 2020
@mjbvz
Copy link
Contributor

mjbvz commented Jun 2, 2020

Potentially related to #25207

If there is enough interest in this, we should also consider what happens when a user wants to write: className={expr ? 'a': 'b'}

@mjbvz mjbvz removed their assignment Jun 2, 2020
@yunti
Copy link
Author

yunti commented Jun 2, 2020

@mjbvz webstorm/pycharm etc... has an option for completion on jsx attributes to be braces, quotes, none or based on type. Based on type defaults to className using quotes and the others using \{}. Which works pretty well.
(pic of the jsx completion options below)
image

@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Jun 9, 2020
@andrewbranch andrewbranch added this to the TypeScript 4.5.0 milestone Aug 26, 2021
@andrewbranch
Copy link
Member

IMO the options should be

  • None
  • Braces
  • Quotes for strings, braces otherwise

(wording negotiable). An option for quotes always is nonsense. What to do for union types that include strings and non-strings, or for any and unknown, is debatable. Inserting braces seems fine; keeping existing behavior and not inserting the = seems fine; inserting just the = with no braces or quotes seems fine.

@armanio123
Copy link
Member

armanio123 commented Sep 15, 2021

Based on type makes sense to me as, it can also be used to avoid adding the suggestion to boolean attributes. For the union types scenario, unless is union with undefined, I think everything should be on braces.

Options:

  • None
  • Braces
  • Based on type

@merlindru
Copy link

Just wanted to leave a big thank you for adding this, super helpful 😄

@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Dec 15, 2021
@shayded-exe
Copy link

shayded-exe commented Aug 10, 2022

If I have it set to braces, it will auto complete a given attribute with braces once.
If I ctrl+z and try completing it again, it just completes the attribute name without braces.

@andrewbranch
Copy link
Member

I can’t reproduce that behavior:

Kapture.2022-08-15.at.12.20.29.mp4

Feel free to file a new issue with more repro info. This one should have been closed as completed.

@Strate
Copy link

Strate commented Nov 23, 2022

It would be nice to auto add braces / quotes when = symbol pressed (like in webstorm).

This is VSCode:

2022-11-23.14.03.33.mov

And this is WebStorm:

2022-11-23.14.05.36.mov

@andrewbranch
Copy link
Member

@Strate I think that would require a new VS Code API; there’s nothing that I know of where an editor asks us to auto-insert code upon insertion of a previous character. Feel free to leave your suggestion on the VS Code repo (be sure to search for duplicates first).

@Strate
Copy link

Strate commented Nov 24, 2022

@andrewbranch isn't auto-closing jsx tag almost same feature?

2022-11-24.13.28.57.mov

@andrewbranch
Copy link
Member

That feature exists purely on the VS Code side; they don’t ask TypeScript for any info to make that happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Rescheduled This issue was previously scheduled to an earlier milestone Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

8 participants