From 7b8510d47764ec7781d6f1216180eb274afd7809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Fri, 24 Apr 2020 11:21:10 +0200 Subject: [PATCH 1/4] Create email input component See #137 --- resources/views/forms/email.blade.php | 4 ++ tests/Feature/FormViewTests/EmailTest.php | 48 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 resources/views/forms/email.blade.php create mode 100644 tests/Feature/FormViewTests/EmailTest.php diff --git a/resources/views/forms/email.blade.php b/resources/views/forms/email.blade.php new file mode 100644 index 00000000..9a0e7981 --- /dev/null +++ b/resources/views/forms/email.blade.php @@ -0,0 +1,4 @@ +@include('kontour::forms.input', [ +'type' => $type ?? 'email', +'name' => $name ?? 'email', +]) \ 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..d4d3072c --- /dev/null +++ b/tests/Feature/FormViewTests/EmailTest.php @@ -0,0 +1,48 @@ + 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); + } +} From a800d53f606c1fce9186570aef3130b8dc327b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Fri, 24 Apr 2020 11:57:03 +0200 Subject: [PATCH 2/4] Test default attributes --- tests/Feature/FormViewTests/EmailTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Feature/FormViewTests/EmailTest.php b/tests/Feature/FormViewTests/EmailTest.php index d4d3072c..b183c59f 100644 --- a/tests/Feature/FormViewTests/EmailTest.php +++ b/tests/Feature/FormViewTests/EmailTest.php @@ -8,6 +8,12 @@ class EmailTest extends IntegrationTest { + public static $defaultEmailAttributes = [ + 'autocomplete' => 'email', + 'autocapitalize' => "none", + 'autocorrect' => "off", + ]; + public function test_input_type_defaults_to_email() { $output = View::make('kontour::forms.email', [ @@ -45,4 +51,15 @@ public function test_input_name_can_be_specified() $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); + } + } } From fac6c03ed7e7d757720b4941a92655bccb4803b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Fri, 24 Apr 2020 15:30:11 +0200 Subject: [PATCH 3/4] Merge controll attributes for email input --- resources/views/forms/email.blade.php | 9 ++++---- tests/Feature/FormViewTests/EmailTest.php | 28 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/resources/views/forms/email.blade.php b/resources/views/forms/email.blade.php index 9a0e7981..e6f6e946 100644 --- a/resources/views/forms/email.blade.php +++ b/resources/views/forms/email.blade.php @@ -1,4 +1,5 @@ -@include('kontour::forms.input', [ -'type' => $type ?? 'email', -'name' => $name ?? 'email', -]) \ No newline at end of file +@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 index b183c59f..93b3fa3b 100644 --- a/tests/Feature/FormViewTests/EmailTest.php +++ b/tests/Feature/FormViewTests/EmailTest.php @@ -10,8 +10,8 @@ class EmailTest extends IntegrationTest { public static $defaultEmailAttributes = [ 'autocomplete' => 'email', - 'autocapitalize' => "none", - 'autocorrect' => "off", + 'autocapitalize' => 'none', + 'autocorrect' => 'off', ]; public function test_input_type_defaults_to_email() @@ -62,4 +62,28 @@ public function test_email_input_has_default_attributes() $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); + } + } } From 3cc09e7aef78bdcbf9897e15a74f7475d1de6fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Fri, 24 Apr 2020 15:34:05 +0200 Subject: [PATCH 4/4] Use email input in auth forms Closes #137 --- resources/views/auth/login.blade.php | 2 +- resources/views/auth/passwords/email.blade.php | 2 +- resources/views/auth/passwords/reset.blade.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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')