Skip to content

Commit 5c90bc5

Browse files
[FormControlRange] Add Open Questions section for backwards FormControlRange (#1152)
Introduces an Open Questions section [raised during CL review](https://chromium-review.googlesource.com/c/chromium/src/+/6876353/3..9/third_party/blink/web_tests/external/wpt/dom/ranges/tentative/FormControlRange-validation.html#14) about how FormControlRange should handle reversed offsets.
1 parent 4cc783e commit 5c90bc5

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

FormControlRange/explainer.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,33 @@ The resulting `AbstractRange` inheritance structure would look like this:
580580
It has been [discussed](https://github.com/whatwg/html/issues/11478#issuecomment-3113360213) that custom elements could also use this API to expose encapsulated ranges, enabling richer editing or selection behaviors while maintaining internal structure.
581581
Such use cases might also prompt revisiting the current `FormControlRange` name in favor of something broader, such as `ElementRange`, to better reflect its applicability beyond form controls.
582582

583+
## Open Questions
584+
How should `FormControlRange` behave when callers provide reversed offsets (i.e. `startOffset > endOffset`)?
585+
586+
Consider the following ideas:
587+
- Throw `IndexSizeError`.
588+
- Convert to a collapsed range (by clipping or reordering endpoints).
589+
- Which direction should the collapse target?
590+
- Collapse to `max(startOffset, endOffset)` (matches DOM `Range`).
591+
- Collapse to `min(startOffset, endOffset)`.
592+
- Preserve a backwards range (allow `startOffset > endOffset` and define direction-aware behavior for text, `toString()`, and layout methods).
593+
594+
Example:
595+
596+
```html
597+
<input value="abcd">
598+
<script>
599+
const range = new FormControlRange();
600+
range.setFormControlRange(input, 4, 0);
601+
// Candidates:
602+
// - Throw: setFormControlRange throws IndexSizeError
603+
// - Collapse: range.startOffset === range.endOffset === 4
604+
// - Backwards: range.startOffset === 4; range.endOffset === 0
605+
</script>
606+
```
607+
608+
Note: With reversed endpoints, DOM `Range` setters collapse them to a single point, whereas `Selection` preserves directionality (anchor/focus). Collapsing is the current interoperable behavior, but alternatives remain open for discussion.
609+
583610
## References & acknowledgements
584611

585612
Many thanks for valuable feedback and advice from:

0 commit comments

Comments
 (0)