Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reveal eye to password form control #2219

Merged
merged 95 commits into from
Sep 11, 2024
Merged
Changes from 7 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
dd32436
Added 'eye-function' to toggle password visibility to form-passwords.
rickyosser Aug 18, 2024
2603659
Fixed coding-style.
rickyosser Aug 18, 2024
2fab4aa
More coding-style fixes.
rickyosser Aug 18, 2024
d2e1f26
More coding-style fixes.
rickyosser Aug 18, 2024
df58eae
More coding-style fixes.
rickyosser Aug 18, 2024
2033e2c
More coding-style fixes.
rickyosser Aug 18, 2024
4db7fb2
More coding-style fixes.
rickyosser Aug 18, 2024
803eb38
More coding fixes and removal of unused variable.
rickyosser Aug 18, 2024
a70548a
More coding fixes and added Override.
rickyosser Aug 18, 2024
7ae6ba1
Hopefully fixed on-click for the eye-button.
rickyosser Aug 18, 2024
43484fb
More coding-style fixes.
rickyosser Aug 18, 2024
0465e40
More coding-style fixes.
rickyosser Aug 18, 2024
e804494
More coding-style fixes.
rickyosser Aug 18, 2024
f25ebf2
More coding-style fixes.
rickyosser Aug 18, 2024
c20806f
More coding-style fixes.
rickyosser Aug 18, 2024
f2acc91
More coding-style fixes.
rickyosser Aug 18, 2024
2c780a0
More coding-style fixes.
rickyosser Aug 18, 2024
74477e6
More coding-style fixes.
rickyosser Aug 18, 2024
b46ad36
More coding-style fixes.
rickyosser Aug 19, 2024
70ee987
More coding-style fixes.
rickyosser Aug 19, 2024
278e6b7
More coding-style fixes.
rickyosser Aug 19, 2024
5354bfe
Added JsExpression templation.
rickyosser Aug 19, 2024
a89083e
Changed JS *_elements to *Elem.
rickyosser Aug 19, 2024
3379a0c
More code-style changes.
rickyosser Aug 19, 2024
731aa26
Added revealEye to password demo in popup.php.
rickyosser Aug 19, 2024
7cb392e
Added behat test for revealEye feature.
rickyosser Aug 19, 2024
d3ffba7
Changed behat tests, trial and error method.
rickyosser Aug 19, 2024
cde7aa1
Added password to input2.php.
rickyosser Aug 19, 2024
28e86f3
Fixed password without and with revealEye.
rickyosser Aug 19, 2024
2d206c4
Changed behat tests, trial and error method.
rickyosser Aug 19, 2024
d4516df
Fixed iconElem in javascript.
rickyosser Aug 19, 2024
177264e
Revert "Fixed iconElem in javascript."
mvorisek Aug 20, 2024
5505bd0
unrevert name - but still wrong, we must pass icon ID, not owning but…
mvorisek Aug 20, 2024
0d2bf39
use "Button::addTo" with correct render region
mvorisek Aug 20, 2024
9c11996
simplify phpdoc
mvorisek Aug 20, 2024
0056683
improve demo
mvorisek Aug 20, 2024
eade929
no guessing icon ID
mvorisek Aug 20, 2024
ada9e67
no action when disabled for consistency
mvorisek Aug 20, 2024
6881832
fix stan
mvorisek Aug 20, 2024
f94b9cd
Test for review of changed revealEye function
rickyosser Aug 20, 2024
9f807c0
Fixed missing comma.
rickyosser Aug 20, 2024
9739fc9
Removed a component used during testing.
rickyosser Aug 20, 2024
adf7c32
Removed variable which wasn't used.
rickyosser Aug 20, 2024
afd397e
Removed Button as we don't use it anymore.
rickyosser Aug 20, 2024
3782518
Testing transparent button on demo.
rickyosser Aug 21, 2024
7d8ae4e
Changed to added button. (Work with input field on('clicl
rickyosser Aug 21, 2024
45a5426
Added comment.
rickyosser Aug 21, 2024
91667e8
Fixed coding-style.
rickyosser Aug 21, 2024
81cc191
More coding-style fixes.
rickyosser Aug 22, 2024
425990b
More coding-style fixes.
rickyosser Aug 22, 2024
5e9c346
Moved code around so ->revealEyeButton and the ->revealEyeButton->on …
rickyosser Aug 22, 2024
46aa901
Removed test-code.
rickyosser Aug 22, 2024
4f300fe
Removed more test-code.
rickyosser Aug 22, 2024
1822f02
Removed UserAction from variable definition.
rickyosser Aug 22, 2024
8ea89d1
Removed console.logs.
rickyosser Aug 22, 2024
d52b59e
Changed using internal Icon to adding an Icon, this works but I need …
rickyosser Aug 23, 2024
5918038
Fixed icon inside field.
rickyosser Aug 23, 2024
a0f8e09
Fixed icon variable.
rickyosser Aug 23, 2024
56336d5
Fixed coding style.
rickyosser Aug 23, 2024
2b5b363
Fixed coding style.
rickyosser Aug 23, 2024
139b47a
Fixed coding style.
rickyosser Aug 23, 2024
b7907d9
Fixed coding style.
rickyosser Aug 23, 2024
03327a9
Cleaned up code for revealEye.
rickyosser Aug 23, 2024
f6d6c9c
Made some behat-test changes.
rickyosser Aug 23, 2024
269edfa
Made some behat-test changes.
rickyosser Aug 23, 2024
675bff6
Made some behat-test changes.
rickyosser Aug 23, 2024
7cb7bc7
Made some behat-test changes.
rickyosser Aug 23, 2024
fa4c032
Made some behat-test changes.
rickyosser Aug 23, 2024
88303ed
Made some behat-test changes.
rickyosser Aug 23, 2024
07455b5
Made some behat-test changes.
rickyosser Aug 23, 2024
88dbac6
Made some behat-test changes.
rickyosser Aug 23, 2024
ad32451
Made some selector changes to behat-test.
rickyosser Aug 23, 2024
16a9f0a
Removed all JavaScript-code for a plain ATK4 implementation.
rickyosser Aug 25, 2024
573e7f1
Fixed coding style.
rickyosser Aug 25, 2024
7182db6
Fixed coding style.
rickyosser Aug 25, 2024
b0728d6
Fixed coding style.
rickyosser Aug 25, 2024
e65a235
Fixed coding style.
rickyosser Aug 25, 2024
92f6894
Simplified code, removed unnecessary variables.
rickyosser Aug 25, 2024
0a238af
Fixed coding style.
rickyosser Aug 25, 2024
419adde
Simplified the code. Removed uneccessary code.
rickyosser Aug 30, 2024
19c1ff8
More simplification of the code. Fixed coding style.
rickyosser Aug 30, 2024
6fbc7f8
Changed behat test to reflect changes in the code.
rickyosser Sep 1, 2024
d7cf049
Reverted to using Javascript to change the fields type otherwise the …
rickyosser Sep 10, 2024
157792e
fix&improve cs
mvorisek Sep 10, 2024
d99fb94
test hide password again
mvorisek Sep 10, 2024
05750aa
test actual reveal
mvorisek Sep 10, 2024
92af85d
make Behat line output short as possible
mvorisek Sep 10, 2024
f7a5d16
cleanup
mvorisek Sep 10, 2024
e973d4e
enable password reveal by default
mvorisek Sep 10, 2024
8b844c2
grey only if disabled, also improves UX/contract
mvorisek Sep 10, 2024
8f0a511
Keep focus on the input-field.
rickyosser Sep 10, 2024
97bbae4
improve cs
mvorisek Sep 11, 2024
b04cadd
fix focus placed to start on reload
mvorisek Sep 11, 2024
924041e
focus input at the end if not focused
mvorisek Sep 11, 2024
271b529
improve phpdoc type
mvorisek Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/Form/Control/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,44 @@

namespace Atk4\Ui\Form\Control;

use Atk4\Ui\Button;
use Atk4\Ui\Js\JsExpression;

class Password extends Line
Copy link
Member

@mvorisek mvorisek Aug 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on whatwg/html#7293 it is true that native solution does not exist in all browsers currently.

IE - at least https://stackoverflow.com/questions/61449079/how-to-hide-the-eye-from-a-password-input-in-ms-edge-and-ie#61450596 is needed to supress the native behaviour of IE, or do we want to keep native eye where supported?

Firefox - https://connect.mozilla.org/t5/ideas/add-a-reveal-password-function-for-logins/idi-p/1140 - did you know there is native (but I agree not much intuitive) reveal - can we turn on/off the native one?

Chrome - it seems there is no native solution (except when using 3rd party extension)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I meant a more native ATK4 solution with more Js functions instead of a big javascript blob... :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IE - I tested Windows 7 and 10, it seems Microsoft does everything to kill IE in favor of Edge - in both systems, when I opened IE, Edge was opened instead. Edge is based on Chrome. And in Edge and Chrome there is no native reveal icon added. So we do not need any additional code to coexist with the native reveal.

{
public string $inputType = 'password';

/**
* @var bool by setting this variable to true you get an Eye-button on the right side which can toggle the visibility of the entered password
*/
public $eye;
mvorisek marked this conversation as resolved.
Show resolved Hide resolved

protected function init(): void

Check failure on line 19 in src/Form/Control/Password.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Method Atk4\Ui\Form\Control\Password::init() overrides method Atk4\Ui\Form\Control::init() but is missing the #[\Override] attribute.
mvorisek marked this conversation as resolved.
Show resolved Hide resolved
{
parent::init();

if ($this->eye) {
$button = new Button([
'class.grey' => true,
'iconRight' => 'eye slash',
]);

$this->action = $button;

$button->on('click', [

Check failure on line 31 in src/Form/Control/Password.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Parameter #2 $selector of method Atk4\Ui\View::on() expects array{Closure(Atk4\Ui\Js\Jquery, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed): (Atk4\Ui\Js\JsExpressionable|Atk4\Ui\View|string|void)}|Atk4\Data\Model\UserAction|Atk4\Ui\Js\JsExpressionable|Atk4\Ui\JsCallback|Atk4\Ui\UserAction\ExecutorInterface|(Closure(Atk4\Ui\Js\Jquery, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed, mixed): (Atk4\Ui\Js\JsExpressionable|Atk4\Ui\View|string|void))|string|null, array{Atk4\Ui\Js\JsExpression} given.
$jsExpression = new JsExpression("
var input_element = document.querySelector(`[id$='form_layout_" . $this->shortName . "_input']`);
var icon_element = document.querySelector(`[id$='" . $this->shortName . "_button_icon']`);

if(input_element.getAttribute('type') == 'password') {
input_element.setAttribute('type', 'text');
icon_element.classList.remove(['slash']);
} else {
input_element.setAttribute('type', 'password');
icon_element.classList.add(['slash']);
}
"),
]);
}
}
}
Loading