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

Commit 2688847

Browse files
authored
Generate ID by name (#40)
1 parent a7d9d2f commit 2688847

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Components/Component.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ public function wireModifier(): ?string
6868
*/
6969
public function id(): string
7070
{
71-
if (!$this->id) {
72-
$this->id = Str::random(4);
71+
if ($this->id) {
72+
return $this->id;
7373
}
7474

75-
return $this->id;
75+
if ($this->name) {
76+
return $this->id = "auto_id_" . $this->name;
77+
}
78+
79+
return $this->id = Str::random(4);
7680
}
7781
}

tests/Feature/BootstrapTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function it_sets_the_id_on_the_label_or_generates_one()
5353

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

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

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

0 commit comments

Comments
 (0)