Skip to content

md-textarea #546

Closed
Closed

Description

@fxck

I would like to add md-textarea. From what I've tried(c&p md-input code, changing selector and template), it should be pretty straightforward, as it just worked without any changes to style or the component itself.

The differences between input and textarea are

  • textarea doesn't have type, step, list attributes
  • textarea might have auto expand/size(probably not needed in the first iteration)

Since 90% of the component is made of annotations, and those cannot be inherited, the way to go(I think) might be either to extend selector

selector: 'md-input,md-textarea',

and use ElementRef to check which selector matched(unless there's a better way I don't know of) and *ngIfthe template to either <input> or <textarea>.

or keep only one selector(that is md-input), and add md-textarea as attribute, and *ngIf the template depending on that.

In both cases I'd be needed add check that type was not added along <md-textarea> or md-textarea, because of _convertValueForInputType, there won't be no need to do anything with step or list, since those simply won't be on the *ngIf'd template.

Thoughts?


as for autosize, there's this tiny thing https://github.com/stevepapa/angular2-autosize

import { ElementRef, HostListener, Directive} from 'angular2/core';

@Directive({
    selector: 'textarea[autosize]'
})

export class Autosize {
 @HostListener('input',['$event.target'])
  onInput(textArea) {
    this.adjust();
  }
  constructor(public element: ElementRef){
  }
  ngOnInit(){
    this.adjust();
  }
  adjust(){
    this.element.nativeElement.style.overflow = 'hidden';
    this.element.nativeElement.style.height = 'auto';
    this.element.nativeElement.style.height = this.element.nativeElement.scrollHeight + "px";
  }
}

which utilizes scrollHeight, which is apparently supported by most browsers https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight

Activity

  1. added
    featureLabel used to distinguish feature request from other issues
    on May 27, 2016
  2. jelbourn commented on May 27, 2016

    @jelbourn
    Contributor

    @hansl did you have any existing plans WRT textarea implementation details?

    I'm thinking it might be good to have a MdTextField base class that both MdInput and MdTextArea extend, mainly so they can set up different bindings. We could possibly also introduce an internal directive like MdTextFieldWrapper that has all the wrapper elements and styles simply content-projects either the input element or textarea element.

    The autosize would be a good follow-up. It would be good to see a simple proof-of-concept on the scrollHeight technique, which would be pretty neat.

  3. fxck commented on May 27, 2016

    @fxck
    ContributorAuthor
  4. naveedahmed1 commented on May 29, 2016

    @naveedahmed1

    @jelbourn can this be added to Alpha.6 milestone?

  5. fxck commented on Jun 1, 2016

    @fxck
    ContributorAuthor

    Any updates? Do those plans exist? cc @jelbourn @hansl

  6. sendilkumarn commented on Jun 1, 2016

    @sendilkumarn
    Contributor

    @fxck for undo and redo can we have something like this

  7. fxck commented on Jun 2, 2016

    @fxck
    ContributorAuthor

    not sure I follow, you want to use React to do undo redo? why would a textarea even need an undo redo, you can do cmd + z, cmd + shift + z?

  8. sendilkumarn commented on Jun 2, 2016

    @sendilkumarn
    Contributor

    Textarea in general, when you continuously type-in, and then do a undo remove all text at once.
    if you take the example undo will remove character by character.

  9. fxck commented on Jun 2, 2016

    @fxck
    ContributorAuthor

    That doesn't really have to do anything with either native textareas or material spec though. Maybe some md-wysiwyg editor, that will be built on top of md-textarea much later on.

  10. naveedahmed1 commented on Jun 2, 2016

    @naveedahmed1

    Aleš I was also wondering what Sendil actually mean by having undo/redo for textarea, but after his recent comment, I revisited the textarea example on react site, and I think could be a really useful feature especially in cases where we have to type in long text. The Github textarea where we type in the comments also have similar functionality, although its a richtext area.

  11. jelbourn commented on Jun 2, 2016

    @jelbourn
    Contributor

    @fxck Feel free to send a PR; we don't have the work scheduled for alpha.6 or 7 right now

  12. fxck commented on Jun 3, 2016

    @fxck
    ContributorAuthor

    @jelbourn should I go with that MdTextField base class, or with my original plan though?

  13. jelbourn commented on Jun 3, 2016

    @jelbourn
    Contributor

    @fxck I would lean towards taking the base class approach; I'm thinking that will end up being cleaner / easier to split up.

  14. cescoferraro commented on Jun 17, 2016

    @cescoferraro

    We would love that!

  15. htafolla commented on Aug 16, 2016

    @htafolla

    @jelbourn @kara any plans to include this in alpah.8 or 9?

  16. alvaro450 commented on Aug 16, 2016

    @alvaro450

    @jelbourn @kara, when do you guys think text area will make it to material components?

  17. paradite commented on Oct 27, 2016

    @paradite

    @jelbourn hi, which stage is this feature in? I see PRs and the issue is closed but on the homepage it is Not started.

  18. fxck commented on Oct 27, 2016

    @fxck
    ContributorAuthor

    It's in master, but not released on npm.

  19. szykov commented on Jan 26, 2017

    @szykov

    I see it's on npm but how to auto-size md-textarea ? Adding attribute md-autosize isn't working for me...
    Is there out of the box solution?

  20. binarious commented on Feb 8, 2017

    @binarious

    @szykov have you tried mdTextareaAutosize? It's in the demo app.

  21. szykov commented on Feb 8, 2017

    @szykov

    @binarious thanks, but I already solved this issue and with the help of this demo app. Wrapping in md-input-container and etc fixed it.

  22. angular-automatic-lock-bot commented on Sep 5, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  23. locked and limited conversation to collaborators on Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions