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

Force focus into HTML5 input #273

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion components/checkbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-checkbox__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-checkbox__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-checkbox use cases
Expand Down
8 changes: 4 additions & 4 deletions components/combobox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-input__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-menu__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-combobox__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-input__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-menu__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-combobox__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-combobox use cases
Expand Down
16 changes: 15 additions & 1 deletion components/combobox/src/auro-combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ export class AuroCombobox extends LitElement {
});

this.addEventListener('focusin', () => {
this.focus();
this.forceInputFocus();
});
}

Expand Down Expand Up @@ -652,6 +652,20 @@ export class AuroCombobox extends LitElement {
this.input.focus();
}

/**
* Forces focus into HTML5 input
* @private
* @returns {void}
*/
forceInputFocus() {
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to experiment with if enabling "delegate focus" helps at all. But otherwise looks good to me.

this.focus();

if (this.input.value) {
// Highlights the text in the datepicker when user tabs into it
this.input.inputElement.setSelectionRange(0, this.input.value.length);
}
}

/**
* Resets component to initial state.
* @returns {void}
Expand Down
2 changes: 1 addition & 1 deletion components/counter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-counter__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-counter__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-counter use cases
Expand Down
8 changes: 4 additions & 4 deletions components/datepicker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-input__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-popover__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-datepicker__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-input__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-popover__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-datepicker__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-datepicker use cases
Expand Down
16 changes: 16 additions & 0 deletions components/datepicker/src/auro-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,20 @@ export class AuroDatePicker extends LitElement {
this.range && focusInput === 'endDate' ? this.inputList[1].focus() : this.inputList[0].focus();
}

/**
* Forces focus into HTML5 input
* @private
* @returns {void}
*/
forceInputFocus() {
// Always force focus into the first input
this.focus();

if (this.value) {
// Highlights the text in the datepicker when user tabs into it
this.inputList[0].inputElement.setSelectionRange(0, this.value.length);
}
}

/**
* Converts valid time number to format used by wc-date-range API.
Expand Down Expand Up @@ -614,6 +628,8 @@ export class AuroDatePicker extends LitElement {
if (this.valueEnd === undefined) {
this.valueEnd = '';
}

this.forceInputFocus();
});

this.addEventListener('focusout', (evt) => {
Expand Down
2 changes: 1 addition & 1 deletion components/dropdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-dropdown__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-dropdown use cases
Expand Down
2 changes: 1 addition & 1 deletion components/form/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-form__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-form__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-form use cases
Expand Down
2 changes: 1 addition & 1 deletion components/input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-input__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-input__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-input use cases
Expand Down
2 changes: 1 addition & 1 deletion components/menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-menu__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-menu__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-menu use cases
Expand Down
2 changes: 1 addition & 1 deletion components/radio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-radio__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-radio__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-radio use cases
Expand Down
6 changes: 3 additions & 3 deletions components/select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ In cases where the project is not able to process JS assets, there are pre-proce
<!-- The below content is automatically added from ../../docs/templates/componentBundleUseModBrowsers.md -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/tokens/CSSCustomProperties.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aurodesignsystem/[email protected]/dist/bundled/essentials.css" />
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-menu__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].30/dist/auro-select__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-dropdown__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-menu__bundled.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit/[email protected].31/dist/auro-select__bundled.js" type="module"></script>
<!-- AURO-GENERATED-CONTENT:END -->

## auro-select use cases
Expand Down
Loading
Loading