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

Field: slots.default() should be called in render #823

Closed
psgoss opened this issue Feb 29, 2024 · 2 comments · Fixed by #834
Closed

Field: slots.default() should be called in render #823

psgoss opened this issue Feb 29, 2024 · 2 comments · Fixed by #834
Labels
bug Something isn't working

Comments

@psgoss
Copy link

psgoss commented Feb 29, 2024

Overview of the problem

Oruga version: 0.8.5
Vuejs version: 3.4.21
OS/Browser: Windows 10 / Chrome

Description

When using the OField component, I get the following warning:

[Vue warn]: Slot "default" invoked outside of the render function: this will not track dependencies used in the slot. Invoke the slot function inside the render function instead. 

This is causing issues with trying to use a bound value for the message and variant properties to show validation errors.

Steps to reproduce

Here's an example component:

<script setup>
import { ref } from 'vue'

const variant = ref(null)
const message = ref(null)

function onClick() {
  variant.value = 'danger'
  message.value = 'This is an error'
}
</script>

<template>
  <o-field
    label="Input"
    horizontal
    :variant="variant"
    :message="message">
    <o-input :maxlength="200" />
  </o-field>

  <o-button @click="onClick">
    Click Me!
  </o-button>
</template>

Expected behavior

When clicking the button, the message should appear below the input and the variant should be applied.

Actual behavior

The warning appears in the console as soon as the component is rendered.

The message appears, and the variant icon appears in the field. But the message text and field border are not getting updated with the variant styling.

If setting variant to a static string value, then the UI appears as you would expect.

@mk-startialab
Copy link
Contributor

I had the same problem and had prepared an environment for inspection.
https://stackblitz.com/edit/vitejs-vite-spyfnj

@mlmoravek mlmoravek added the bug Something isn't working label Mar 2, 2024
@mlmoravek
Copy link
Member

The unchanged variant class was an unknown bug, thanks for spotting this. (see #834)

The "Vue warning" is a known issue that occurs when moving from the option api to the composition api. The `addons' feature of the OField component needs to check the default slot children. This is done by creating the slot from the template in a function.

const slot = slots.default();

This was a working behaviour in the options api. However, it is not a good implementation for the composition api.
I think the template of OField needs to be refactored and changed so that a template ref can be used instead to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants