Skip to content

Pro Version Feature Proposal: Expose Wire Elements ID to Component Instance #522

@GC-Max

Description

@GC-Max

Within the registerAndActivateComponent method, an ID is generated that Wire Elements uses to uniquely track the component instances.

Currently, this ID is not accessible from within the instantiated component class itself. Although an event is dispatched:
$this->dispatch("{$this->determineComponentType()}.componentActivated", id: $id);
…it is emitted before the component is fully instantiated. As a result, components are unable to listen for this event at the time it fires.

One example of why this would be helpful is when listening for modal.closing events, there's no reliable way for a component to determine whether the event relates to itself - because it doesn’t know the wire elements ID assigned to it.

I propose passing the wire elements ID as an argument to the component by adding the below code to the registerAndActivateComponent method.

if(array_key_exists('wireElementsAssignedID', $arguments)) {
     throw new UnexpectedValueException("The 'wireElementsAssignedID' key is reserved and cannot be used in component arguments.");
}
$arguments['wireElementsAssignedID'] = $id;

TLDR:
This feature would allow user land code know the modals id. There currently is no way to guarantee this even if you set the elementId($arguments) method as it is initially called statically, you need to rerun this method when the modal is instantiated and make sure to provide the same exact arguments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions