@@ -135,7 +135,7 @@ public function addClass(array|string $value): Html
135
135
/**
136
136
* Add a class based on a boolean value.
137
137
*/
138
- public function addClassIf (bool $ check , string $ class_name_1 = '' , string $ class_name_0 = '' ): Html
138
+ public function addClassIf (? bool $ check , string $ class_name_1 = '' , string $ class_name_0 = '' ): Html
139
139
{
140
140
return $ this ->addClass ($ check ? $ class_name_1 : $ class_name_0 );
141
141
}
@@ -145,7 +145,7 @@ public function addClassIf(bool $check, string $class_name_1 = '', string $class
145
145
*
146
146
* @param mixed ...$attr
147
147
*/
148
- public function addAttrIf (bool $ check , ...$ attr ): Html
148
+ public function addAttrIf (? bool $ check , ...$ attr ): Html
149
149
{
150
150
if ($ check ) {
151
151
return $ this ->attr (...$ attr );
@@ -495,9 +495,9 @@ public function hidden(): Html
495
495
/**
496
496
* Shortcut to set('href', $value). Only works with A tags.
497
497
*/
498
- public function href (string $ value = '' ): Html
498
+ public function href (? string $ value = '' ): Html
499
499
{
500
- if ($ this ->tag === 'a ' ) {
500
+ if ($ this ->tag === 'a ' && ! is_null ( $ value ) ) {
501
501
return parent ::attr ('href ' , $ value );
502
502
}
503
503
@@ -757,19 +757,19 @@ public function rows(int|string $rows): Html
757
757
/**
758
758
* Add an route link.
759
759
*/
760
- public function route (string $ text , string $ route , array $ parameters = [], string $ target = '' ): Html
760
+ public function route (? string $ text , string $ route , array $ parameters = [], string $ target = '' ): Html
761
761
{
762
762
$ href = route ($ route , $ parameters );
763
763
$ href .= !empty ($ target ) ? '# ' .$ target : '' ;
764
764
765
- return $ this ->addElement ('a ' )->text ($ text )
765
+ return $ this ->addElement ('a ' )->text ($ text ?? '' )
766
766
->href ($ href );
767
767
}
768
768
769
769
/**
770
770
* Add an route href.
771
771
*/
772
- public function routeHref (string $ route , array $ parameters = [], string $ target = '' ): Html
772
+ public function routeHref (? string $ route , array $ parameters = [], string $ target = '' ): Html
773
773
{
774
774
$ href = route ($ route , $ parameters );
775
775
$ href .= !empty ($ target ) ? '# ' .$ target : '' ;
@@ -882,7 +882,7 @@ public function src(string $value): Html
882
882
/**
883
883
* Add a style based on a boolean value.
884
884
*/
885
- public function addStyleIf (bool $ check , string $ style_1 = '' , string $ style_0 = '' ): Html
885
+ public function addStyleIf (? bool $ check , string $ style_1 = '' , string $ style_0 = '' ): Html
886
886
{
887
887
return $ this ->style ($ check ? $ style_1 : $ style_0 );
888
888
}
@@ -945,16 +945,20 @@ public function text($value, ...$args): Html
945
945
*
946
946
* @param mixed $args
947
947
*/
948
- public function textIf (bool $ test , string $ value , ...$ args ): Html
948
+ public function textIf (? bool $ test , string $ value , ...$ args ): Html
949
949
{
950
950
return $ test ? $ this ->text ($ value , ...$ args ) : $ this ;
951
951
}
952
952
953
953
/**
954
954
* Shortcut to set('title', $value).
955
955
*/
956
- public function title (string $ value ): Html
956
+ public function title (? string $ value ): Html
957
957
{
958
+ if (is_null ($ value )) {
959
+ return $ this ;
960
+ }
961
+
958
962
return parent ::attr ('title ' , $ value );
959
963
}
960
964
0 commit comments