diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index b8f81b4a..1cfee68d 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -11,7 +11,7 @@
{{ __('Login') }}
@csrf - @include('kontour::forms.input', ['name' => 'email', 'type' => 'email', 'controlAttributes' => ['required', 'autocomplete' => 'email']]) + @include('kontour::forms.email', ['controlAttributes' => ['required']]) @include('kontour::forms.input', ['name' => 'password', 'type' => 'password', 'controlAttributes' => ['required', 'autocomplete' => 'current-password']]) @include('kontour::forms.checkbox', ['name' => 'remember', 'label' => __('Remember Me')]) @component('kontour::buttons.generic') diff --git a/resources/views/auth/passwords/email.blade.php b/resources/views/auth/passwords/email.blade.php index 3fe558a1..c730869a 100644 --- a/resources/views/auth/passwords/email.blade.php +++ b/resources/views/auth/passwords/email.blade.php @@ -13,7 +13,7 @@ @csrf - @include('kontour::forms.input', ['name' => 'email', 'type' => 'email', 'controlAttributes' => ['required', 'autocomplete' => 'email']]) + @include('kontour::forms.email', ['controlAttributes' => ['required']]) @component('kontour::buttons.generic') {{ __('Send Password Reset Link') }} @endcomponent diff --git a/resources/views/auth/passwords/reset.blade.php b/resources/views/auth/passwords/reset.blade.php index 311f96e9..09e47e1c 100644 --- a/resources/views/auth/passwords/reset.blade.php +++ b/resources/views/auth/passwords/reset.blade.php @@ -11,7 +11,7 @@ @csrf - @include('kontour::forms.input', ['name' => 'email', 'type' => 'email', 'controlAttributes' => ['required', 'autocomplete' => 'email']]) + @include('kontour::forms.email', ['controlAttributes' => ['required']]) @include('kontour::forms.input', ['name' => 'password', 'type' => 'password', 'controlAttributes' => ['required', 'autocomplete' => 'new-password']]) @include('kontour::forms.input', ['name' => 'password_confirmation', 'type' => 'password', 'controlAttributes' => ['required', 'autocomplete' => 'new-password']]) @component('kontour::buttons.generic') diff --git a/resources/views/forms/email.blade.php b/resources/views/forms/email.blade.php new file mode 100644 index 00000000..e6f6e946 --- /dev/null +++ b/resources/views/forms/email.blade.php @@ -0,0 +1,5 @@ +@include('kontour::forms.input', ['type' => $type ?? 'email', 'name' => $name ?? 'email', +'controlAttributes' => array_merge( +['autocomplete' => 'email', 'autocapitalize' => 'none', 'autocorrect' => 'off'], +$controlAttributes ?? [] +)]) \ No newline at end of file diff --git a/tests/Feature/FormViewTests/EmailTest.php b/tests/Feature/FormViewTests/EmailTest.php new file mode 100644 index 00000000..93b3fa3b --- /dev/null +++ b/tests/Feature/FormViewTests/EmailTest.php @@ -0,0 +1,89 @@ + 'email', + 'autocapitalize' => 'none', + 'autocorrect' => 'off', + ]; + + public function test_input_type_defaults_to_email() + { + $output = View::make('kontour::forms.email', [ + 'errors' => new MessageBag, + ])->render(); + + $this->assertRegExp('//', $output); + } + + public function test_input_type_can_be_specified() + { + $output = View::make('kontour::forms.email', [ + 'errors' => new MessageBag, + 'type' => 'text', + ])->render(); + + $this->assertRegExp('//', $output); + } + + public function test_input_name_defaults_to_email() + { + $output = View::make('kontour::forms.email', [ + 'errors' => new MessageBag, + ])->render(); + + $this->assertRegExp('//', $output); + } + + public function test_input_name_can_be_specified() + { + $output = View::make('kontour::forms.email', [ + 'name' => 'test', + 'errors' => new MessageBag, + ])->render(); + + $this->assertRegExp('//', $output); + } + + public function test_email_input_has_default_attributes() + { + $output = View::make('kontour::forms.email', [ + 'errors' => new MessageBag, + ])->render(); + + foreach (self::$defaultEmailAttributes as $attribute => $default) { + $this->assertStringContainsString("$attribute=\"$default\"", $output); + } + } + + public function test_control_attributes_can_be_set() + { + $output = View::make('kontour::forms.email', [ + 'errors' => new MessageBag, + 'controlAttributes' => [ + 'autocomplete' => 'off', + 'autocapitalize' => 'on', + 'autocorrect' => 'on', + 'required', + 'a' => 'b', + ] + ])->render(); + + $this->assertRegExp('/\s+autocomplete="off"\W/', $output); + $this->assertRegExp('/\s+autocapitalize="on"\W/', $output); + $this->assertRegExp('/\s+autocorrect="on"\W/', $output); + $this->assertRegExp('/\s+required\W/', $output); + $this->assertRegExp('/\s+a="b"\W/', $output); + + foreach (self::$defaultEmailAttributes as $attribute => $default) { + $this->assertStringNotContainsString("$attribute=\"$default\"", $output); + } + } +}