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

toucan-form: Expose named blocks for textarea #149

Merged

Conversation

ynotdraw
Copy link
Contributor

@ynotdraw ynotdraw commented Apr 25, 2023

🚀 Description

This PR attempts to expose all named blocks from textarea within toucan-form. This is more of a conversation PR to see if we want to go with this approach due to the limitations with named blocks.

Depending on how this goes, I'll update all the other components as well (maybe via a feature branch for smaller PRs).


🔬 How to Test

  • Green Build

📸 Images/Videos of Functionality

M/A

@ynotdraw ynotdraw self-assigned this Apr 25, 2023
@changeset-bot
Copy link

changeset-bot bot commented Apr 25, 2023

⚠️ No Changeset found

Latest commit: 0ac0249

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

@github-actions
Copy link
Contributor

github-actions bot commented Apr 25, 2023

Preview URLs

Env: preview
Docs: https://797772cc.ember-toucan-core.pages.dev

Copy link
Contributor Author

@ynotdraw ynotdraw Apr 25, 2023

Choose a reason for hiding this comment

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

I described the issue in the comment here, but TL;DR:

The issue is we cannot do something like:

<@form.Field @name={{@name}} as |field|>
  <Form::Fields::Textarea
    @hint={{@hint}}
    @error={{this.mapErrors field.rawErrors}}
    @value={{this.assertString field.value}}
    {{! @glint-expect-error }}
    @onChange={{field.setValue}}
    @isDisabled={{@isDisabled}}
    @isReadOnly={{@isReadOnly}}
    @rootTestSelector={{@rootTestSelector}}
    name={{@name}}
    ...attributes
  >
    {{#if (has-block 'label')}}
      <:label>{{yield to='label'}}</:label>
    {{/if}}
  </Form::Fields::Textarea>
</@form.Field>

Or else we get the following due to emberjs/rfcs#735:

Build Error (PackagerRunner) in ../packages/ember-toucan-form/dist/-private/textarea-field.js

Module build failed (from ember-toucan-core/node_modules/.pnpm/thread-loader@3.0.4_webpack@5.75.0/node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 5)
$TMPDIR/embroider/835ae7/packages/ember-toucan-form/dist/-private/textarea-field.js/textarea-field.js: Unexpected named block nested in a normal block:

|
|
|        <:label>{{yield to='label'}}</:label>
|
|

(error occurred in '$TMPDIR/embroider/835ae7/packages/ember-toucan-form/dist/-private/textarea-field.js' @ line 33 : column 31)

Essentially we have two layers of named blocks here:

  1. In Form::Fields::Textarea - this is the source of the named blocks
  2. When users use our <form.Textarea component in toucan-form

Due to this nesting, essentially passing blocks from a higher level component to a lower level one does not work as you'd expect. We essentially need something like splat-blocks or something I think to solve this?

Copy link
Contributor

@simonihmig simonihmig left a comment

Choose a reason for hiding this comment

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

I agree the implementation does not really look beautiful, but that's not our fault. We already used some "wilder" patterns that are making things easy and powerful at the same time for consumers while accepting increased complexity on our (library maintainers) side. And I think that choice is reasonable here.

@ynotdraw ynotdraw changed the title (PoC) toucan-form: Expose named blocks for textarea toucan-form: Expose named blocks for textarea Apr 26, 2023
@ynotdraw ynotdraw changed the base branch from main to feature-toucan-form-named-blocks April 26, 2023 12:07
@ynotdraw ynotdraw marked this pull request as ready for review April 26, 2023 12:07
@ynotdraw ynotdraw force-pushed the toucan-form-expose-named-blocks branch from cf7599a to 85e9e76 Compare April 26, 2023 12:08
ynotdraw and others added 2 commits April 26, 2023 08:09
…a-test.gts

Co-authored-by: nicole chung <771170+nicolechung@users.noreply.github.com>
@ynotdraw
Copy link
Contributor Author

Thanks y'all for the feedback and discussion. I went ahead and created [feature-toucan-form-named-blocks](https://github.com/CrowdStrike/ember-toucan-core/tree/feature-toucan-form-named-blocks). I'm going to use that as my feature branch to keep PRs small, and then once everything is "feature complete", I'll put that PR up for merging into main 🎉

@ynotdraw ynotdraw merged commit 728fbbf into feature-toucan-form-named-blocks Apr 26, 2023
14 checks passed
@ynotdraw ynotdraw deleted the toucan-form-expose-named-blocks branch April 26, 2023 12:17
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.

None yet

3 participants