findAndReplaceDOMText icon indicating copy to clipboard operation
findAndReplaceDOMText copied to clipboard

support text in textarea elements

Open skhavari opened this issue 10 years ago • 4 comments

Repro

  • append <textarea>lorem ipsum</textarea> to the demo contents
  • then search for lorem

Expect

  • lorem in the text area to by styled

Actual

  • lorem in the text area vanishes

skhavari avatar Oct 29 '14 23:10 skhavari

This is probably a legit issue, but I'm not sure how it should be fixed, or what the desirable behaviour is. Textarea inner-text (its value) is not interpreted as HTML so there's no actual way to style 'lorem' in your case (e.g. you could not wrap it in a custom <span> for example).

The correct behaviour is probably to entirely ignore anything within a <textarea> OR to allow replacement but with the knowledge that it'll only be able to replace the found string with another string (so replacing 'lorum', in your example, with 'foo', would work).

padolsey avatar Nov 02 '14 18:11 padolsey

at minimum the inner-text of the textarea shouldn't be modified. currently text that match in the textarea vanishes.

skhavari avatar Nov 02 '14 19:11 skhavari

I agree.

FWIW, for now, you can use filterElements to avoid the textarea:

findAndReplaceDOMText(elementToSearchIn, {
  find: /lorem/,
  wrap: 'em',
  filterElements: function(node) {
    return node.nodeName.toLowerCase() !== 'textarea';
  }
});

padolsey avatar Nov 02 '14 19:11 padolsey

Then there might be the issue of contenteditable textarea's (or contenteditable elements of any kind) which could reasonably allow the element wrapping...

brettz9 avatar Feb 12 '15 16:02 brettz9