Signal not being passed to parent

Hello,

I have a grid that with several tiles, and when a tile is clicked, it fetches data and navigates to a new screen. During the fetching, I want to display a loading spinner and hide the grid. I am trying to use signals so that the grid tile can communicate to the grid component when enter is clicked. I have followed the documentation on signals, and I am doing everything according to the docs, but the signal is not being fired to the grid component, nor the parent component as a whole.

GridTile.js

export default class GridTile extends Lightning.Component {
    ...
    _handleEnter() {
        this.signal('enterClicked');
        fetchSomeData()
    }
}

PageWithGrid.js

export default class PageWithGrid extends Lightning.Component {
    static _template() {
        return {
            Grid: {
                ...
                type: Grid,
                signals: {
                    enterClicked: true,
                },
            },
            ...
        }
    }
    
    enterClicked() {
        // do something
    }

    _setup() {
        ...
        this.tag('Grid').add(this.loadedItems) // array of Grid Tiles
    }
}

Let me know if there is something I’m doing wrong and how to do it right, or if this is in fact correct.

Thanks!

I think you need:

signals: {
                    enterClicked: 'enterClicked',
                },

Also make sure the GridTile is a direct descendent. Otherwise you can use fireAncestors

I’ve tried using the name of the function as a string like that, but it also doesn’t work. According to the docs, setting it to true is the same thing since true means it shares the same name.

Could you clarify what a direct descendent is in this context? The grid tiles are the items inside of the grid, so I would assume that the parent of the tiles is the grid component, is this not correct?

Context wise:

Grid Item > Grid > Your page

So, the signal from the grid item is being sent to the Grid component. You better off using fireAncestors.

So how would I use fireAncestors in this context?

_handleEnter() {
        this.fireAncestors('$enterClicked');
        fetchSomeData()
    }

Grid needs function

$enterClicked() {
        // do something
    }
1 Like

I’m having this same issue whilst building a list of buttons. The signal must be being passed to the List component each time and therefore it will never work?

I’d rather not use fireAncestors because of the way I have to then go and register them and it’s not really how I want to organise my code base since I would end up with a huge fireancestors map.

Is there no other way to achieve this within the framework?

I don’t want to use States either since that would be a lot of boiler plate for my list of buttons…