Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Clear button always being visible in Playroom TextFields #1725

Merged
merged 4 commits into from
Mar 26, 2025

Conversation

jahredhope
Copy link
Member

@jahredhope jahredhope commented Mar 2, 2025

Edit: switched solution to option 1

Problem

Currently when not setting onClear on a TextField the Clear button (Cross on the right side) isn't visible in applications and the documentation site.

Example: Documentation Site - No Clear Button

example-docs-site-no-clear-button

However, it is visible in Playroom, due to Playroom's automatic injection of state handling.

Example: Playroom - Clear Button

example-playroom-has-clear-button

This creates a discrepancy between what users see in docs examples and playrooms, and makes it impossible create playrooms where the Clear button is not visible.

Solution

Avoid passing onClear through to the TextField in Playroom when it's falsy.

To make it easy for prototyping to add the clear field behaviour allow passing true instead of a no-op function.

<TextField
  label="Label"
  stateName="field1"
  onClear={true}
/>

Example: Playroom - With Change now has no Clear button

When onClear is not provided:

<TextField
  label="Label"
  stateName="field1"
/>

There would now be no clear button:

example-playroom-no-close-with-change

Playroom

Alternative Options

The downside with the above solution is that playrooms now use invalid code onClear={true} in prototypes that can't be copied into application code.

Alternative 1 - Opt-out of Clear label: We could default to showing the Clear button (as we do currently) but allow passing onClear={false} to deliberately opt-out of the clear label.

<TextField
  label="Label"
  stateName="field1"
  onClear={false}
/>

This makes the minimal change, doesn't effect existing playrooms but doesn't fix the disconnect between examples and playrooms.

Alternative 2 - Authentic behaviour: We could simply not allow passing a boolean in, requiring users to enter a dummy function onClear={() => {}} to activate the clear button.

<TextField
  label="Label"
  stateName="field1"
  onClear={() => {}}
/>

This may be confusing to playroom users who aren't familiar with JavaScript as well as breaking existing playrooms.

@jahredhope jahredhope requested a review from a team as a code owner March 2, 2025 23:47
Copy link

changeset-bot bot commented Mar 2, 2025

⚠️ No Changeset found

Latest commit: 521a1a9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@felixhabib felixhabib force-pushed the allow-no-clearable branch 2 times, most recently from 43e4173 to 75912c7 Compare March 26, 2025 05:36
Comment on lines +229 to +238
description: (
<Notice tone="info">
<Text>
When prototyping in Playroom, fields will automatically include a{' '}
<TextLink href="/components/IconClear">clear icon</TextLink> and
clearing functionality. To disable this behaviour, set{' '}
<Strong>onClear</Strong> to <Strong>false</Strong>.
</Text>
</Notice>
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Putting the docs messaging below the example to reduce prominence. Happy for suggestions otherwise

Copy link
Member Author

Choose a reason for hiding this comment

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

Love it

@felixhabib felixhabib merged commit dcefe17 into master Mar 26, 2025
6 checks passed
@felixhabib felixhabib deleted the allow-no-clearable branch March 26, 2025 06:25
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.

2 participants