Skip to content

Commit

Permalink
feat: switch search field placeholder depending on the view
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rita committed Oct 21, 2024
1 parent 96ed25e commit 284e284
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 16 additions & 1 deletion components/header-bar/src/command-palette/command-palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { colors, spacers } from '@dhis2/ui-constants'
import { IconApps24 } from '@dhis2/ui-icons'
import PropTypes from 'prop-types'
import React, { useState, useCallback, useRef, useEffect } from 'react'
import i18n from '../locales/index.js'
import ActionsMenu from './sections/actions-menu.js'
import BackButton from './sections/back-button.js'
import Container from './sections/container.js'
Expand Down Expand Up @@ -82,7 +83,21 @@ const CommandPalette = ({ apps, commands, shortcuts }) => {
{show ? (
<Container setShow={setShow} show={show}>
<div data-test="headerbar-menu" className="headerbar-menu">
<Search value={filter} onChange={handleFilterChange} />
<Search
value={filter}
onChange={handleFilterChange}
placeholder={
currentView === 'home'
? i18n.t('Search apps, shortcuts, commands')
: currentView === 'apps'
? i18n.t('Search apps')
: currentView === 'commands'
? i18n.t('Search commands')
: currentView === 'shortcuts'
? i18n.t('Search shortcuts')
: null
}
/>
<div className="headerbar-menu-content">
{currentView !== 'home' && !filter ? (
<BackButton onClickHandler={goToDefaultView} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { IconSearch16 } from '@dhis2/ui-icons'
import PropTypes from 'prop-types'
import React from 'react'
import { InputField } from '../../../../input/src/input-field/input-field.js'
import i18n from '../../locales/index.js'

function Search({ value, onChange }) {
function Search({ value, onChange, placeholder }) {
return (
<>
<InputField
value={value}
name="filter"
placeholder={i18n.t('Search apps, shortcuts, commands')}
placeholder={placeholder}
onChange={onChange}
initialFocus
className="search"
Expand Down Expand Up @@ -50,6 +49,7 @@ function Search({ value, onChange }) {
Search.propTypes = {
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
placeholder: PropTypes.string,
}

export default Search

0 comments on commit 284e284

Please sign in to comment.