Modify a attribute using event handlers from the main template

I've been experimenting with designing components using FASTElement. But I've hit a roadblock trying to pass a dynamic property from parent to child component. Here's a snippet of my design, featuring two FAST templates:

childCompTemplate.ts

const myChildComponent = () => html<ChildModel>`<div class=${x => x.customTheme!.someSpecialClassName}`>
    <!-- some stuff -->
</div>`

parentCompTemplate.ts

const myParentComp = () => html<ParentModel>`<div @mouseEnter=${x => x.customTheme!.handleMouseEnterEvent()} @mouseExit=${x => x.customTheme!.handleMouseExit()}`>
    <my-child-component :customTheme=${x => x.customTheme} />
</div>`

CustomTheme.ts

public class CustomTheme {
    @observable someSpecialClassName: string;
    /* Some other props and functions */

    public handleMouseEnter() {
        this.someSpecialClassName = "foo";
    }

    public handleMouseExit() {
        this.someSpecialClassName = "bar";
    }

In my model files, I made reference to the customTheme property:

ParentModel.ts <= this is an interface

...
customTheme?: CustomTheme;
...

ChildModel.ts

...
@observable customTheme?: CustomTheme;
...

But despite triggering the event, I'm not seeing any changes in the child component's div class. Can someone point out what I might be missing?

Appreciate any assistance provided!

TL;DR I need to update a property when a specific event occurs in the parent template, but the changes aren't reflected in the child.

Answer №1

It seems like this situation should be successful. One detail that caught my attention is the event names you are using. Instead of @mouseEnter and @mouseExit, I believe it would be better to use @mouseenter and @mouseleave. It's possible that the events are not triggering, causing the state change to not occur as intended.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The function was operational before, but currently it is indicating that it is no longer functioning as a

I encountered an issue with my code where a service that was previously working has suddenly stopped functioning and is now displaying an error message stating that it's not a function. Thanks to Sajeetharan for helping me out initially. constructo ...

Using ng2 to retrieve an object from an HttpGet service

I'm currently facing an issue with retrieving JSON data from my WebAPI. Every time I attempt to use the returned object in my component, it displays as undefined. The goal is to showcase student and course data on the homepage of my website. Currentl ...

I am looking to extend my App's MUI theme to include customized MUI components from a 3rd party library. How can I achieve this?

I am currently developing a personalized MUI component library that will be utilized by multiple applications. My goal is to ensure that the components in the library align with the theme of the specific app that is using them. For instance, I have create ...

Intercept Axios Responses - Retrieving API Responses for HTTP Statuses that are not in the 200 range

I've set up a custom Axios instance with interceptors for handling responses. As per the Axios documentation, the success interceptor is triggered for 2xx statuses while the error interceptor handles any other status codes. My goal is to show an error ...

The React-Typescript error message is stating that the module "react-router-dom" does not have the exported member "RouteComponentProps"

I encountered an issue with my project involving a login page and the usage of "RouteComponentProps". Unfortunately, I received the following error: Module '"react-router-dom"' has no exported member 'RouteComponentProps'. Upon attempt ...

Difficulty in loading the uploaded API data into the template

I am facing an issue with a service that retrieves user data based on the Token stored in localStorage. The data is returned correctly until it reaches my component. The problem lies in the code snippet present in my component.ts file: https://i.sstatic.n ...

Avoiding the stacking of event listeners in React onClick when removing and re-adding the same listener

Is it possible to remove and add the same event listener in an onClick React event? The goal is to have an event listener added to the parent element when the target element is clicked, and then removed on the next click to prevent stacking. One issue tha ...

Guide on incorporating Firebase "onSnapshot" listener values to update a Vue "ref" variable

I have implemented a Vue composable feature that utilizes a Firebase onSnapshot listener to track data changes. The goal is to update a ref called documentsArray whenever there is a change detected by the listener. Interestingly, when I log the contents ...

IntersectionObserver activates prior to element's entrance into the viewport

I've set up a Vue component with the following structure: <template> <article> <!-- This content spans several viewport heights: you *have* to scroll to get to the bottom --> {{ content }} </article> <span ref ...

Steps for creating a table with a filter similar to the one shown in the image below

https://i.sstatic.net/zR2UU.png I am unsure how to create two sub-blocks within the Business A Chaud column and Potential Business Column. Thank you! I managed to create a table with input, but I'm struggling to replicate the PUSH & CtoC Column for ...

When using Typescript, you may encounter the error message "Declaration file for module 'xmlhttprequest' not found."

When trying to use the following code on Node: import { XMLHttpRequest } from 'xmlhttprequest'; I encountered the following error while compiling with tsc: index.ts|4 col 32 error| 7016[QF available]: Could not find a declaration file for mo ...

Troubleshooting issue with the functionality of nodejs async await flow

My goal is to implement an endpoint that allows users to download a video and then upload it to YouTube. Here is the process I follow: First, I extract the video URL from the request body. Next, I save the video to a temporary folder. After that, I procee ...

Issue with TypeScript: variable lacks an initializer and is not explicitly assigned within the constructor

Code: class Example { private server: string; constructor() { this.setServer(); } setServer(): void { this.server = 'server'; } } new Example(); Error: ⨯ Unable to compile TypeScript: src/index.ts:309:13 ...

The functionality of the Angular click event binding seems to be malfunctioning

When I click on a radio button, I want to see relevant selections. Below are the files: app.component.html <div class="col-md-3"> <b>Select Category</b><br> <input type="radio" name="colors" [(ngModel)]="typing" (clic ...

The wildcard syntax for importing statements in Angular 2

I created multiple classes in a single file with the following structure file: myclasses.ts export class Class1 {....} export class Class2 {....} export class Class3 {....} Now I am attempting to import all of them using a wildcard like this import {*} ...

The value of the provider in the context remains constant

In my latest React+Typescript project, I am diving into learning ContextAPI. My goal is to handle locale and authentication functionalities efficiently. While trying to initialize my context values required by Typescript / eslint for the login/logout fun ...

The typescript error TS2339 is triggered by the property 'webkitURL' not being found on the 'Window' type

Currently utilizing Angular 2 in a project that is compiled with TypeScript. Encountering an issue when attempting to generate a blob image: Error TS2339: Property 'webkitURL' does not exist on type 'Window' The TypeScript code causi ...

Issue with Angular 8: ng lint error - Reached maximum call stack size limit

I am facing an issue with linting my project. When I run "ng lint," I encounter the following error: $ ng lint Linting "app"... An unhandled exception occurred: Maximum call stack size exceeded See "C:\Users\6100BR~1\AppData\Local&bsol ...

How is it possible that TypeScript does not provide a warning when a function is called with a different number of arguments than what is expected?

I am working on a vanilla JavaScript project in VS Code and have set up jsconfig.json. Here is an example of the code I am using: /** * @param {(arg: string) => void} nestedFunction */ function myFunction(nestedFunction) { // Some logic here } myFu ...

@vx/enhanced responsiveness with TypeScript

I am currently utilizing the @vx/responsive library in an attempt to retrieve the width of a parent component. Below are snippets from my code: import * as React from 'react' import { inject, observer } from 'mobx-react' import { IGlob ...