Commit Graph
606 Commits
Author SHA1 Message Date
Sean Doyle 86390c3e3b Add TrixEditorElement.form property
The problem:
---

Consider the following HTML:

```html
<form action="/articles" method="post">
  <textarea name="content"></textarea>

  <button type="submit">Save</button>
</form>
```

Then, consider a theoretical event listener:

```js
addEventListener("keydown", ({ key, metaKey, target }) => {
  if (target.form && key == "Enter" && (metaKey || ctrlKey)) {
    form.requestSubmit()
  }
})
```

This relies on [HTMLTextAreaElement.form][] finding its related `<form>`
element. Given the way the `[form]` attribute can reference a `<form>`
element that is _not an ancestor_, that same event listener would
continue to work with this HTML:

```html
<textarea name="content" form="new_article"></textarea>

<!-- elsewhere -->
<form id="new_article" action="/articles" method="post">
  <button type="submit">Save</button>
</form>
```

Unfortunately, if the `<textarea>` element were replaced with a
`<trix-editor>`, the event listener's reliance on accessing the `form`
as a property would break, since the `<trix-editor>` custom element
doesn't declare that property.

[HTMLTextAreaElement.form]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement#properties

The proposed changes:
---

Provide property access for `<trix-editor>` elements, similar to how an
`<input>` or `<textarea>` element can access a form outside of its
direct tree of ancestors via the [form="..."][] attribute and the
corresponding `.form` property.

Related testing changes
---

All other system tests in the suite are rendered into a `<form
id="trix-container">` element on the page. In order to test this new
behavior, the fixture HTML declare several new `<form>` elements.

These are incompatible with an ancestor `<form>`, since HTML forbids
nesting `<form>` elements.

To address that, this commit changes the implementation of how its Test
Helpers create elements from the fixture HTML files.

[form="..."]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-form
2021-04-26 10:02:07 -04:00
Javan Makhmali 66d26af0fd Pin automated Chrome tests to v89 pending further investigation 2021-04-22 11:51:11 -04:00
Javan Makhmali 417c2be5ee Avoid Firefox execCommand insert list bug when there's only a single line of text 2021-04-22 11:38:40 -04:00
Javan Makhmali 75d0f7e981 Travis CI → GitHub Actions 2020-11-20 09:44:02 -05:00
Javan Makhmali 9601ac9bc1 Ensure JSON.parse() errors don't interrupt parsing HTML 2020-11-19 15:16:07 -05:00
Javan Makhmali f81b606cd0 Skip parsing <iframe>s 2020-11-19 14:33:12 -05:00
Javan Makhmali ea81c02df0 Tidy accessibility tests 2020-11-05 11:14:34 -05:00
Sean Doyle 5cc0bab37e Ensure trix-editor element is ARIA labeled
Since the `<trix-editor>` element is custom and not a browser `<input>`,
we can't rely that assistive technology will be able to [read the label
text from a `<label for="...">` that corresponds to a `<trix-editor
id="...">` element][labelable].

When a `<trix-editor>` element is attached to the DOM and initialized,
collect the text from its related `<label>` elements and combine it to
set a default `[aria-label]` value.

If the `<trix-editor>` element is a descendant of any of its `<label>`
elements, *omit* those elements when generating an `[aria-label]` value.

If an [`[aria-label]` value][aria-label] is already specified, *do not*
override it.

Similarly, if a [`[aria-labelledby]` value][aria-labelledby] is
specified, don't set the `[aria-label]` attribute at all.

[labelable]: https://html.spec.whatwg.org/multipage/forms.html#category-label
[aria-label]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute
[aria-labelledby]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute
2020-11-04 21:28:40 -05:00
Javan Makhmali 8458f0645f Exclude <label>s that control another element 2020-09-24 11:51:38 -04:00
Javan Makhmali a4b8f01156 Group <label> tests and use a dedicated fixture 2020-09-24 11:50:31 -04:00
Sean Doyle 0a55749cf7 code review feedback 2020-09-15 13:48:14 -04:00
Sean Doyle 7cc6d9e5e6 Focus <trix-editor> on <label> click
Both `<input>` elements and `<textarea>` elements' JavaScript Object
interfaces support the `.labels` property ([HTMLInputElement.labels][]
and [HTMLTextAreaElement.labels][], respectively).

This commit adds the `TrixEditorElement.labels` property to match.

When corresponding `<label>` elements exist within the `.labels`
property, wire-up [`click` event listeners][mdn-click-event] that focus
the corresponding `<trix-editor>` elements.

[HTMLInputElement.labels]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/labels
[HTMLTextAreaElement.labels]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement/labels
[mdn-click-event]: https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event
2020-09-15 11:47:51 -04:00
Javan Makhmali 8bfcade89b Empty blocks can be grouped regardless of direction 2020-08-13 17:26:48 -04:00
Javan Makhmali b354e3f30d Add (automatic) RTL text support 2020-08-12 15:57:50 -04:00
Nabeelah AliandJavan Makhmali e1a6a37731 Respect newlines implied by block elements (#773)
* Respect non-empty block elements by allowing them to create a new block, also ensure unwrapped text nodes preceeded by a block element are demarcated with a newline

* Clean up extraneous method

* More robustly, look at the previous sibling rather than element sibling

* Refactor coffeescript to be more pleasing

* Update to ensure we don't create unncessary blocks; instead prefer newlines where possible

* Update test names to be more descriptive

* Add a test for deeply nested divs

* Refactor logic to avoid mocking the guards

* Refactor tests

* Add some intentionally failing tests to investigate

* Skip failing test cases for now

refs: 1f265dd6b8

* Remove extraneous whitespace

Co-authored-by: Javan Makhmali <javan@javan.us>
2020-07-30 12:25:50 -04:00
Abdulwahaab AhmedandJavan Makhmali 107123b7f8 Sanitize pasted URLs (#793)
* Treat pasted URLs as HTML

Addressing feedback comments

* Update test/src/system/pasting_test.coffee

Co-authored-by: Javan Makhmali <javan@javan.us>

Fixing broken test

Removing newline char and space char
2020-05-29 16:44:14 -04:00
Javan Makhmali 8223961416 Freshen test dependencies 2020-04-16 16:22:03 -04:00
Javan Makhmali 760a863316 CI: Freshen browser test matrix 2020-03-09 15:05:34 -07:00
Steve Johnson 2bd8aaef73 Parse text after closing tag as separate block (#742)
* Parse text after closing tag as seperate block

* Fixed typo

* Moved and simplified test, paired isBlockElement call with containerElement check
2020-02-13 15:29:39 -08:00
Javan Makhmali 94654f4a1b Add regression test for #732 2020-01-31 11:02:56 -05:00
Javan MakhmaliandClayton Smith 5bd3c13c8d Sanitize href attributes with javascript: protocol
Closes #712

Co-Authored-By: Clayton Smith <clayton-shopify@users.noreply.github.com>
2020-01-09 14:43:58 -05:00
Javan Makhmali 3792dbd11f Fix missing test helper import
References: c9460b4c73
2019-11-27 19:59:00 -05:00
Javan Makhmali c9460b4c73 Change html check to prevent xss 2019-11-27 16:55:34 -05:00
Javan Makhmali d6071f565a CI: Freshen test dependencies and browsers 2019-08-29 11:27:18 -04:00
Javan Makhmali 867f289a85 CI: Fix running tests on Sauce Labs mobile simulators
Android devices stopped connecting to localhost for unknown reasons, but 0.0.0.0 works. iOS 12.2 displays some kind of error (Selenium?) that’s too small to read so pinning to 12.0 for now.
2019-08-29 10:57:34 -04:00
Javan Makhmali 71bfb8870d Fix intermittent test failures 2019-08-16 12:52:40 -04:00
Javan Makhmali be7fca764f Preserve original <img> dimensions if present when loading HTML
Fixes #668
2019-08-16 12:51:24 -04:00
Javan Makhmali 286cf2470d Fix parsing nested block elements at different nesting levels
Fixes #352
2019-08-14 11:33:13 -04:00
Javan Makhmali d4edd23495 Fix parsing text nodes following block elements
Fixes #663
2019-08-14 09:16:44 -04:00
Javan Makhmali 692e2fdda8 Fix rendering identical blocks after re-parsing HTML
Fixes #662. Regression introduced very subtly (by me) in #355.
2019-08-13 14:40:45 -04:00
Javan Makhmali 4be52bd31c Merge pull request #650 from basecamp/dependabot/npm_and_yarn/test/lodash-4.17.14
Bump lodash from 4.17.11 to 4.17.14 in /test
2019-07-15 08:44:56 -04:00
Javan Makhmali f75f0d305c CI: Freshen browser list 2019-07-15 08:38:09 -04:00
dependabot[bot] a6014cb279 Bump lodash from 4.17.11 to 4.17.14 in /test
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.11 to 4.17.14.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.11...4.17.14)

Signed-off-by: dependabot[bot] <support@github.com>
2019-07-13 19:24:08 +00:00
Vincent Robert bf4e02aa33 Add test about undoing block attributes 2019-05-14 11:00:52 +02:00
Javan Makhmali 4fff711a76 Fix handling link pastes in Safari
Upstream report: https://bugs.webkit.org/show_bug.cgi?id=196702
2019-04-08 15:24:50 -04:00
Javan Makhmali d9143c0d60 Fix deleting the last character in a composed word on Android
Regression introduced in https://github.com/basecamp/trix/commit/c518d03506a9689c8c27eaac4776a8a47f244dd0
2019-04-04 10:18:56 -04:00
Javan Makhmali f01ac664f3 Improve Paste and Match Style operations in Chrome
Work around https://bugs.chromium.org/p/chromium/issues/detail?id=934448
2019-02-27 10:02:58 -08:00
Javan Makhmali 1f3bafa287 Handle Tab+Shift keydown → decreaseNestingLevel 2019-02-26 08:52:06 -08:00
Javan Makhmali 39291a6cb4 Fix handling spelling corrections in Safari 2019-02-22 18:25:40 -08:00
Javan Makhmali ae9900634c Fix test failures on iOS 2019-02-22 18:24:06 -08:00
Javan Makhmali a592b4ba66 Fix that text copied from MS Word would be pasted as an image 2019-02-22 17:42:21 -08:00
Javan Makhmali e4e7606730 Add file pasting tests 2019-02-22 17:05:43 -08:00
Javan Makhmali 861ba0ecdc Synchronize rendering with animation frames 2019-01-14 08:21:41 -05:00
Javan Makhmali 89ae150993 Fix that typing over a selected attachment would format the text with all disabled attributes 2019-01-11 08:19:09 -05:00
Javan Makhmali 47c1490794 Condition more tests by input event support level 2019-01-07 14:34:34 -05:00
Javan Makhmali c5958ba101 Merge branch 'master' into level-2-input
# Conflicts:
#	.blade.yml
2019-01-07 13:47:06 -05:00
Javan Makhmali dc615d10c7 CI: Blade Runner → Karma Runner 2019-01-07 13:16:48 -05:00
Javan Makhmali 01691f4dcb Fix failing tests in Safari 11 2019-01-07 09:04:16 -05:00
Javan Makhmali 516dd8c7a0 Handle Tab keydown → increaseNestingLevel 2019-01-04 16:25:05 -05:00
Javan Makhmali bcc5045053 Fix intermittent test failures 2019-01-04 15:31:50 -05:00