Skip to content

fix: allow text in read-only components to be selected#4417

Merged
jperals merged 2 commits into
cloudscape-design:mainfrom
TrevorBurnham:read-only-selectable-text
May 7, 2026
Merged

fix: allow text in read-only components to be selected#4417
jperals merged 2 commits into
cloudscape-design:mainfrom
TrevorBurnham:read-only-selectable-text

Conversation

@TrevorBurnham
Copy link
Copy Markdown
Contributor

Fixes #4411

This PR modifies the styles on DateRangePicker, FileTokenGroup, Select and Multiselect to make text selectable.

Testing

I've added a read-only toggle to the demo pages and was able to manually test each of these.

  • Changes are covered with new/existing unit tests? No
  • Changes are covered with new/existing integration tests? No

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@TrevorBurnham TrevorBurnham requested a review from a team as a code owner April 8, 2026 18:52
@TrevorBurnham TrevorBurnham requested review from jperals and removed request for a team April 8, 2026 18:52
@TrevorBurnham TrevorBurnham changed the title Allow text in read-only components to be selected fix: Allow text in read-only components to be selected Apr 8, 2026
@TrevorBurnham TrevorBurnham changed the title fix: Allow text in read-only components to be selected fix: allow text in read-only components to be selected Apr 8, 2026
@TrevorBurnham TrevorBurnham force-pushed the read-only-selectable-text branch from 227fc00 to 119d85c Compare April 8, 2026 19:21
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.41%. Comparing base (2d19b0f) to head (42c67fd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4417   +/-   ##
=======================================
  Coverage   97.41%   97.41%           
=======================================
  Files         933      933           
  Lines       29577    29577           
  Branches    10753    10752    -1     
=======================================
  Hits        28813    28813           
- Misses        716      757   +41     
+ Partials       48        7   -41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jperals
Copy link
Copy Markdown
Member

jperals commented Apr 15, 2026

Would it be possible to add coverage, maybe with the Selection API? https://developer.mozilla.org/en-US/docs/Web/API/Selection


// read-only in-filtering-token (i.e. for property filter readOnlyOperations)
// should retain standard borders, only the icon changes
&.readonly:not(&.disabled):not(&.in-filtering-token) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: probably a minor use case, but the :not(&.in-filtering-token) excludes from this fix read-only operator selectors in property filter:
Image

At the same time, we would prefer placeholder text to not be selectable, because that comes with collateral a11y issues (if it is interactive, it will have other requirements such as contrast):

Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the user-select: text to a separate &.readonly:not(&.disabled) rule that also covers filtering tokens. I've also added user-select: none to .placeholder.

@TrevorBurnham TrevorBurnham force-pushed the read-only-selectable-text branch from 8de254f to 2998c7c Compare May 5, 2026 21:17
@TrevorBurnham
Copy link
Copy Markdown
Contributor Author

I've rebased the branch, added test coverage (see the new "Read-only mode" describe block), and addressed your comments

};

test(
'trigger text is selectable via the Selection API',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should assert that the text is selectable via user interaction, not via the Selection API. The Selection API can be used for verification.

One way you can select text in tests is by double-clicking, with the caveat that the will only select part of the text (in this case, "2018") when it contains separators such as dashes.

Proposed:

    test(
      'trigger text is selectable',
      setupReadOnlyTest(async (page, browser) => {
        const triggerSelector = page.dateRangePickerTrigger;
        const triggerText = await page.getTriggerText();
        expect(triggerText).toContain('2018-01-09');

        const element = browser.$(triggerSelector);
        await element.doubleClick();

        const selectedText = await browser.execute(() => window.getSelection()?.toString());
        expect(selectedText).not.toBeFalsy();
        expect(triggerText).toContain(selectedText);
      })

- Apply `user-select: text` to all read-only button-triggers (including
  those inside property-filter tokens, i.e. `readOnlyOperations`), while
  keeping `form-readonly-element` borders scoped to the non-filtering
  case. Fixes the gap where read-only property-filter operator text was
  still unselectable.
- Set `user-select: none` on the custom placeholder spans in Select
  (`.placeholder`) and DateRangePicker (`.label-text`). When these
  components are read-only without a value, the trigger renders
  placeholder text; preserving its non-selectable nature avoids
  accessibility concerns that accompany selectable/interactive text.
- Add a DateRangePicker integration test that double-clicks the read-only
  trigger to simulate a real user selection and verifies via the
  Selection API that the selected text comes from the trigger's content.
  Double-click is gated by `user-select`, so this actually exercises
  the fix (unlike a programmatic Range, which works regardless).
@TrevorBurnham TrevorBurnham force-pushed the read-only-selectable-text branch from 3102a88 to 42c67fd Compare May 6, 2026 17:44
@jperals jperals added this pull request to the merge queue May 7, 2026
Merged via the queue into cloudscape-design:main with commit ef48a29 May 7, 2026
47 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Text in read-only date range picker is unselectable

2 participants