Skip to content

Exposing a variable as readonly #7891

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

Closed
ClementNerma opened this issue Sep 25, 2022 · 2 comments
Closed

Exposing a variable as readonly #7891

ClementNerma opened this issue Sep 25, 2022 · 2 comments

Comments

@ClementNerma
Copy link

Describe the problem

I have a variable that changes inside my component, like this:

<script lang="ts">
import { Focusable } from "..."
let focused = false
</script>

<Focusable onFocus={() => { focused = true }} onUnfocus={() => { focused = false }} />

I want to expose focused such as in other components I can do:

<script lang="ts">
let focused: boolean
</script>

<MyComponent bind:focused />

Describe the proposed solution

I don't know how this could be done - any idea?

Alternatives considered

Importance

would make my life easier

@Prinzhorn
Copy link
Contributor

https://github.com/sveltejs/svelte/search?q=readonly+binding&type=issues
It this it? #7712

Or maybe you're new to Svelte and if you don't mind it being two way all your code is missing is an export.

<script lang="ts">
import { Focusable } from "..."
-let focused = false
+export let focused = false
</script>

<Focusable onFocus={() => { focused = true }} onUnfocus={() => { focused = false }} />

@ClementNerma
Copy link
Author

Seems like it is. I'm not new to Svelte but I absolutely want a one-way binding, hence the read-only requirement.

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

2 participants