-
Notifications
You must be signed in to change notification settings - Fork 6
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
ynotdraw
merged 3 commits into
feature-toucan-form-named-blocks
from
toucan-form-expose-named-blocks
Apr 26, 2023
+162
−17
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
95 changes: 81 additions & 14 deletions
95
packages/ember-toucan-form/src/-private/textarea-field.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,83 @@ | ||
{{! | ||
Regarding Conditionals | ||
|
||
This looks really messy, but Form::Fields::Textarea exposes named blocks; HOWEVER, | ||
we cannot conditionally render named blocks due to /~https://github.com/emberjs/rfcs/issues/735. | ||
|
||
We *can* conditionally render components though, based on the blocks and argument combinations | ||
users provide us. This is very brittle, but until /~https://github.com/emberjs/rfcs/issues/735 | ||
is resolved and a solution is found, this appears to be the only way to truly expose | ||
conditional named blocks. | ||
|
||
--- | ||
|
||
Regarding glint-expect-error | ||
|
||
"@onChange" of the textarea only expects a string typed value, but field.setValue is generic, | ||
accepting anything that DATA[KEY] could be. Similar case with "@value", but there casting to | ||
a string is easy. | ||
}} | ||
<@form.Field @name={{@name}} as |field|> | ||
<Form::Fields::Textarea | ||
@label={{@label}} | ||
@hint={{@hint}} | ||
@error={{this.mapErrors field.rawErrors}} | ||
@value={{this.assertString field.value}} | ||
{{! The issue here is that onChange of textarea only expects a string typed value, but field.setValue is generic, accepting anything that DATA[KEY] could be. Similar case with @value, but there casting to a string is easy. }} | ||
{{! @glint-expect-error }} | ||
@onChange={{field.setValue}} | ||
@isDisabled={{@isDisabled}} | ||
@isReadOnly={{@isReadOnly}} | ||
@rootTestSelector={{@rootTestSelector}} | ||
name={{@name}} | ||
...attributes | ||
/> | ||
{{#if (this.hasOnlyLabelBlock (has-block 'label') (has-block 'hint'))}} | ||
<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 | ||
> | ||
<:label>{{yield to='label'}}</:label> | ||
</Form::Fields::Textarea> | ||
{{else if (this.hasHintAndLabelBlocks (has-block 'label') (has-block 'hint')) | ||
}} | ||
<Form::Fields::Textarea | ||
@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 | ||
> | ||
<:label>{{yield to='label'}}</:label> | ||
<:hint>{{yield to='hint'}}</:hint> | ||
</Form::Fields::Textarea> | ||
{{else if (this.hasLabelArgAndHintBlock @label (has-block 'hint'))}} | ||
<Form::Fields::Textarea | ||
@label={{@label}} | ||
@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 | ||
> | ||
<:hint>{{yield to='hint'}}</:hint> | ||
</Form::Fields::Textarea> | ||
{{else}} | ||
ynotdraw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{{! Argument-only case }} | ||
<Form::Fields::Textarea | ||
@label={{@label}} | ||
@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}} | ||
</@form.Field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
Or else we get the following due to emberjs/rfcs#735:
Essentially we have two layers of named blocks here:
Form::Fields::Textarea
- this is the source of the named blocks<form.Textarea
component intoucan-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?