Skip to content

Commit

Permalink
fix: textarea value property (#445)
Browse files Browse the repository at this point in the history
closes #442
  • Loading branch information
g105b committed Oct 19, 2023
1 parent 7fcc147 commit 69935b0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/HTMLElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,9 @@ protected function __prop_get_value():string {

return $this->options[$this->selectedIndex]->value;
}
elseif($this->elementType === ElementType::HTMLTextAreaElement) {
return $this->nodeValue;
}

return $this->textContent;
}
Expand Down Expand Up @@ -832,6 +835,9 @@ protected function __prop_set_value(string $value):void {
}
}
}
elseif($this->elementType === ElementType::HTMLTextAreaElement) {
$this->nodeValue = $value;
}
else {
$this->setAttribute("value", $value);
}
Expand Down
11 changes: 11 additions & 0 deletions test/phpunit/HTMLElement/HTMLElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,15 @@ public function testToString():void {
$sut->textContent = uniqid();
self::assertSame("", (string)$sut);
}

public function testValue_textarea():void {
$document = new HTMLDocument();
$sut = $document->createElement("textarea");
$sut->value = "example123";
self::assertSame("<textarea>example123</textarea>", $sut->outerHTML);
self::assertFalse($sut->hasAttribute("value"));

$sut->innerHTML = "changed value";
self::assertSame("changed value", $sut->value);
}
}
6 changes: 0 additions & 6 deletions test/phpunit/HTMLElement/HTMLTextAreaElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ public function testCols():void {
self::assertPropertyAttributeCorrelateNumber($sut, "int:20", "cols");
}

public function testDefaultValue():void {
$document = new HTMLDocument();
$sut = $document->createElement("textarea");
self::assertPropertyAttributeCorrelate($sut, "value", "defaultValue");
}

public function testMaxLength():void {
$document = new HTMLDocument();
$sut = $document->createElement("textarea");
Expand Down

0 comments on commit 69935b0

Please sign in to comment.