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

feat(form): allow composition #297

Open
ayoayco opened this issue Mar 30, 2023 · 5 comments
Open

feat(form): allow composition #297

ayoayco opened this issue Mar 30, 2023 · 5 comments

Comments

@ayoayco
Copy link
Member

ayoayco commented Mar 30, 2023

Currently, we only expose the Form component and all the control components are rendered and ordered according to the configuration.

We should next allow users of the library to compose the form as they want.

It should look something like

<Form>
  <TextInput />
  <TextArea />
  <RadioGroup>
    <Radio />
    <Radio />
    <Radio />
  </RadioGroup>
</Form>
@Icyscools
Copy link
Member

Should we map the FormControl name and the component in this way?

const form = new FormGroup([
  {
    name: 'username',
    label: 'Username',
  },
  {
    name: 'password',
    label: 'Password',
    type: 'password',
  }
]
---
<Form formGroups={form}>
  <TextInput name="username" />
  <TextInput name="password" />
</Form>

We add a attribute name for each component . When it have name, it'll try to map the FormControl in the FormGroup first.

@ayoayco
Copy link
Member Author

ayoayco commented Mar 30, 2023

Yes exactly.

What I am unsure of right now is if we still need the control components or can we just use HTML elements directly

<Form formGroups={formgrp}>
  <input name="username" />
  <input name="password" />
</Form>

@Icyscools
Copy link
Member

I'm not quite sure how to access the components in slots.

Looking on this. It said:

Unlike props, which are attributes passed to an Astro component available for use throughout your component with Astro.props, slots render child HTML elements where they are written.

so, I think it can't be possible to access the components in slots which we passed from the parent components.

Any idea? @ayoayco @fazzaamiarso

@fazzaamiarso
Copy link
Member

@Icyscools if I'm right, you can access child nodes with assignedNode() https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/assignedNodes

@Icyscools
Copy link
Member

Not sure if we can access that via server-side. But it's worth to try. Thanks! @fazzaamiarso

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

No branches or pull requests

3 participants