Skip to content

Commit

Permalink
change(search): added search icon as button for proper accessibility …
Browse files Browse the repository at this point in the history
…support [ACCESSIBILITY 2.1.1.1] #360 from eea/refactor-search-input-icon
  • Loading branch information
ichim-david authored Jul 24, 2023
2 parents 10d90ed + f96a590 commit 8f932ff
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/helpers/eventHandlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function handleEnterKeyPress(event, callback) {
if (event.key === 'Enter') {
event.preventDefault();
callback(event);
}
}
1 change: 1 addition & 0 deletions src/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export useClickOutside from './useClickOutside';
export usePrevious from './usePrevious';
export useFirstVisited from './useFirstVisited';
export handleEnterKeyPress from './eventHandlers';
20 changes: 9 additions & 11 deletions src/ui/Header/HeaderSearchPopUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect } from 'react';
import { Container, Input, List } from 'semantic-ui-react';
import { withRouter, Link } from 'react-router-dom';
import { useClickOutside } from '@eeacms/volto-eea-design-system/helpers';
import { handleEnterKeyPress } from '@eeacms/volto-eea-design-system/helpers';

const getRandomItems = (arr, max) => {
return (
Expand Down Expand Up @@ -37,7 +38,6 @@ function HeaderSearchPopUp({
} = activeView || {};
const { suggestionsTitle, suggestions, maxToShow } = searchSuggestions || {};

const [text, setText] = React.useState('');
const [visibleSuggestions, setVisibileSuggestions] = React.useState(
getRandomItems(suggestions, maxToShow),
);
Expand All @@ -48,12 +48,8 @@ function HeaderSearchPopUp({

useClickOutside({ targetRefs: [nodeRef, ...triggerRefs], callback: onClose });

const onChangeText = (event, { value }) => {
setText(value);
event.preventDefault();
};

const onSubmit = (event) => {
const text = searchInputRef?.current?.inputRef?.current?.value;
history.push(`${path}?q=${text}`);

if (window?.searchContext?.resetSearch) {
Expand All @@ -79,12 +75,14 @@ function HeaderSearchPopUp({
<form method="get" onSubmit={onSubmit}>
<Input
ref={searchInputRef}
className="search"
onChange={onChangeText}
icon={{
className: 'ri-search-line',
link: true,
className="icon search"
action={{
className: 'icon ri-search-line',
'aria-label': 'Submit search',
onClick: onSubmit,
onKeyDown: (event) => {
handleEnterKeyPress(event, onSubmit);
},
}}
placeholder={placeholder}
fluid
Expand Down
25 changes: 19 additions & 6 deletions theme/themes/eea/elements/input.overrides
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
.accordion-title:not(.active) .ui.input input {
color: @textColorCSSVar;
}

.ui.input input {
border: @border;

Expand Down Expand Up @@ -121,26 +122,38 @@ textarea.fluid {
font-weight: @bold;
}

i.icon {
.icon {
position: absolute;
top: 0;
right: 0;
height: 100%;
margin: 0;
background-color: transparent !important;
box-shadow: none !important;
line-height: 1;
text-align: center;
}

.icon:before {
color: @white;
font-size: 16px;
opacity: 1;
}
}

.ui.fluid.icon.input.search > input::-webkit-input-placeholder {
opacity: 0.9;
color: rgb(255, 255, 255);
opacity: 0.9;
}

.ui.fluid.icon.input.search > input::-moz-placeholder {
opacity: 0.9;
color: rgb(255, 255, 255);
opacity: 0.9;
}

.ui.fluid.icon.input.search > input::-ms-input-placeholder {
opacity: 0.9;
color: rgb(255, 255, 255);
opacity: 0.9;
}

@media only screen and (min-width: @tabletBreakpoint) {
Expand All @@ -150,7 +163,7 @@ textarea.fluid {
font-size: 18px;
}

i.icon {
.icon:before {
font-size: 18px;
}
}
Expand All @@ -164,7 +177,7 @@ textarea.fluid {
font-size: 40px;
}

i.icon {
.icon:before {
font-size: 38px;
}
}
Expand Down

0 comments on commit 8f932ff

Please sign in to comment.