From dbd3de50bc29fba55cfbc89fbc1dfc1db78dac6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20=C4=8Ciko=C5=A1?= Date: Tue, 23 Feb 2021 15:05:07 +0100 Subject: [PATCH 1/2] LPS-127020 Add attribute to set auto-focus on search input --- .../context/ManagementToolbarDefaults.java | 4 ++++ .../servlet/taglib/ManagementToolbarTag.java | 19 +++++++++++++++++++ .../ManagementToolbarDisplayContext.java | 4 ++++ .../main/resources/META-INF/liferay-clay.tld | 6 ++++++ .../management_toolbar/ManagementToolbar.js | 2 ++ .../management_toolbar/SearchControls.js | 2 ++ 6 files changed, 37 insertions(+) diff --git a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/internal/servlet/taglib/display/context/ManagementToolbarDefaults.java b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/internal/servlet/taglib/display/context/ManagementToolbarDefaults.java index b8ef42a93db072..5b42500bbe657b 100644 --- a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/internal/servlet/taglib/display/context/ManagementToolbarDefaults.java +++ b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/internal/servlet/taglib/display/context/ManagementToolbarDefaults.java @@ -47,6 +47,10 @@ public static Boolean isDisabled() { return false; } + public static Boolean isSearchInputAutoFocus() { + return false; + } + public static Boolean isSelectable() { return true; } diff --git a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/servlet/taglib/ManagementToolbarTag.java b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/servlet/taglib/ManagementToolbarTag.java index 331a7c8b310e3c..e42f8424dafe3e 100644 --- a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/servlet/taglib/ManagementToolbarTag.java +++ b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/servlet/taglib/ManagementToolbarTag.java @@ -310,6 +310,18 @@ public Boolean isDisabled() { return _disabled; } + public Boolean isSearchInputAutoFocus() { + if (_searchInputAutoFocus == null) { + if (_managementToolbarDisplayContext != null) { + _managementToolbarDisplayContext.isSearchInputAutoFocus(); + } + + return ManagementToolbarDefaults.isSearchInputAutoFocus(); + } + + return _searchInputAutoFocus; + } + public Boolean isSelectable() { if (_selectable == null) { if (_managementToolbarDisplayContext != null) { @@ -465,6 +477,10 @@ public void setSearchFormName(String searchFormName) { _searchFormName = searchFormName; } + public void setSearchInputAutoFocus(Boolean searchInputAutoFocus) { + _searchInputAutoFocus = searchInputAutoFocus; + } + public void setSearchInputName(String searchInputName) { _searchInputName = searchInputName; } @@ -566,6 +582,7 @@ protected void cleanUp() { _searchContainerId = null; _searchFormMethod = null; _searchFormName = null; + _searchInputAutoFocus = null; _searchInputName = null; _searchValue = null; _selectable = null; @@ -624,6 +641,7 @@ protected Map prepareProps(Map props) { props.put("searchFormMethod", searchFormMethod); props.put("searchFormName", _namespace(namespace, getSearchFormName())); + props.put("searchInputAutoFocus", isSearchInputAutoFocus()); props.put( "searchInputName", _namespace(namespace, getSearchInputName())); props.put("searchValue", getSearchValue()); @@ -1166,6 +1184,7 @@ private void _writeLabelItem( private String _searchContainerId; private String _searchFormMethod; private String _searchFormName; + private Boolean _searchInputAutoFocus; private String _searchInputName; private String _searchValue; private Boolean _selectable; diff --git a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/servlet/taglib/display/context/ManagementToolbarDisplayContext.java b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/servlet/taglib/display/context/ManagementToolbarDisplayContext.java index 92822462dc5379..917f83a54e290f 100644 --- a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/servlet/taglib/display/context/ManagementToolbarDisplayContext.java +++ b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/java/com/liferay/frontend/taglib/clay/servlet/taglib/display/context/ManagementToolbarDisplayContext.java @@ -138,6 +138,10 @@ public default Boolean isDisabled() { return false; } + public default Boolean isSearchInputAutoFocus() { + return ManagementToolbarDefaults.isSearchInputAutoFocus(); + } + public default Boolean isSelectable() { return true; } diff --git a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/liferay-clay.tld b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/liferay-clay.tld index dd4b5f278ba54f..65a017d1fc8281 100644 --- a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/liferay-clay.tld +++ b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/liferay-clay.tld @@ -1755,6 +1755,12 @@ false true + + + searchInputAutoFocus + false + true + searchInputName diff --git a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/resources/management_toolbar/ManagementToolbar.js b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/resources/management_toolbar/ManagementToolbar.js index 0c3d48d18d1eb3..b6e0e0523e8685 100644 --- a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/resources/management_toolbar/ManagementToolbar.js +++ b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/resources/management_toolbar/ManagementToolbar.js @@ -53,6 +53,7 @@ function ManagementToolbar({ searchData, searchFormMethod, searchFormName, + searchInputAutoFocus, searchInputName, searchValue, selectAllURL, @@ -116,6 +117,7 @@ function ManagementToolbar({ searchData={searchData} searchFormMethod={searchFormMethod} searchFormName={searchFormName} + searchInputAutoFocus={searchInputAutoFocus} searchInputName={searchInputName} searchMobile={searchMobile} searchValue={searchValue} diff --git a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/resources/management_toolbar/SearchControls.js b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/resources/management_toolbar/SearchControls.js index 9948f5194e7008..1746254118e7d0 100644 --- a/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/resources/management_toolbar/SearchControls.js +++ b/modules/apps/frontend-taglib/frontend-taglib-clay/src/main/resources/META-INF/resources/management_toolbar/SearchControls.js @@ -23,6 +23,7 @@ const SearchControls = ({ searchData, searchFormMethod, searchFormName, + searchInputAutoFocus, searchInputName, searchMobile, searchValue, @@ -39,6 +40,7 @@ const SearchControls = ({ Date: Tue, 23 Feb 2021 15:10:51 +0100 Subject: [PATCH 2/2] LPS-127020 Add sample use of auto-focus on search input --- .../META-INF/resources/partials/management_toolbars.jsp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/apps/frontend-taglib/frontend-taglib-clay-sample-web/src/main/resources/META-INF/resources/partials/management_toolbars.jsp b/modules/apps/frontend-taglib/frontend-taglib-clay-sample-web/src/main/resources/META-INF/resources/partials/management_toolbars.jsp index 345d2b4e93853c..1467f0f4f6fe40 100644 --- a/modules/apps/frontend-taglib/frontend-taglib-clay-sample-web/src/main/resources/META-INF/resources/partials/management_toolbars.jsp +++ b/modules/apps/frontend-taglib/frontend-taglib-clay-sample-web/src/main/resources/META-INF/resources/partials/management_toolbars.jsp @@ -31,6 +31,7 @@ ClaySampleManagementToolbarsDisplayContext managementToolbarsDisplayContext = ne filterDropdownItems="<%= managementToolbarsDisplayContext.getFilterDropdownItems() %>" searchActionURL="mySearchActionURL?key1=val1&key2=val2&key3=val3" searchFormName="mySearchName" + searchInputAutoFocus="<%= true %>" searchInputName="mySearchInputName" selectable="<%= true %>" sortingOrder="desc"