Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Generate ID by name (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet authored Dec 22, 2020
1 parent a7d9d2f commit 2688847
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Components/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ public function wireModifier(): ?string
*/
public function id(): string
{
if (!$this->id) {
$this->id = Str::random(4);
if ($this->id) {
return $this->id;
}

return $this->id;
if ($this->name) {
return $this->id = "auto_id_" . $this->name;
}

return $this->id = Str::random(4);
}
}
2 changes: 1 addition & 1 deletion tests/Feature/BootstrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function it_sets_the_id_on_the_label_or_generates_one()

$inputId = $page->crawler()->filter('input[type="text"]')->attr('id');

$this->assertEquals(4, strlen($inputId));
$this->assertStringStartsWith("auto_id_", $inputId);

$page
->seeElement('input[id="' . $inputId . '"]')
Expand Down

0 comments on commit 2688847

Please sign in to comment.