-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
fix: handle forward-delete properly in the amount text input #25815
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4f8386e
handle forward-delete properly in the amount text input
akinwale 6a0d797
Merge remote-tracking branch 'upstream/main' into task-25578
akinwale acd68df
handle Control-D keyboard shortcut on iOS
akinwale e99accb
fix edge-case with iOS Safari's handling of the Control key for the k…
akinwale ac07f86
use a constant to match for the 'control' key press
akinwale a814bae
fix merge conflict
akinwale ace45f1
fix more merge conflicts
akinwale a88c1b3
tidy up TextInputWithCurrencySymbol refactor
akinwale 998e56c
use anonymous function for onSelectionChange
akinwale fd28e88
fix merge conflict
akinwale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import AmountTextInput from '../AmountTextInput'; | ||
import CurrencySymbolButton from '../CurrencySymbolButton'; | ||
import * as CurrencyUtils from '../../libs/CurrencyUtils'; | ||
import useLocalize from '../../hooks/useLocalize'; | ||
import * as MoneyRequestUtils from '../../libs/MoneyRequestUtils'; | ||
import * as textInputWithCurrencySymbolPropTypes from './textInputWithCurrencySymbolPropTypes'; | ||
|
||
function TextInputWithCurrencySymbol(props) { | ||
const {fromLocaleDigit} = useLocalize(); | ||
const currencySymbol = CurrencyUtils.getLocalizedCurrencySymbol(props.selectedCurrencyCode); | ||
const isCurrencySymbolLTR = CurrencyUtils.isCurrencySymbolLTR(props.selectedCurrencyCode); | ||
|
||
const currencySymbolButton = ( | ||
<CurrencySymbolButton | ||
currencySymbol={currencySymbol} | ||
onCurrencyButtonPress={props.onCurrencyButtonPress} | ||
/> | ||
); | ||
|
||
/** | ||
* Set a new amount value properly formatted | ||
* | ||
* @param {String} text - Changed text from user input | ||
*/ | ||
const setFormattedAmount = (text) => { | ||
const newAmount = MoneyRequestUtils.addLeadingZero(MoneyRequestUtils.replaceAllDigits(text, fromLocaleDigit)); | ||
props.onChangeAmount(newAmount); | ||
}; | ||
|
||
const amountTextInput = ( | ||
<AmountTextInput | ||
formattedAmount={props.formattedAmount} | ||
onChangeAmount={setFormattedAmount} | ||
placeholder={props.placeholder} | ||
ref={props.forwardedRef} | ||
selection={props.selection} | ||
onSelectionChange={(e) => { | ||
props.onSelectionChange(e); | ||
}} | ||
onKeyPress={props.onKeyPress} | ||
/> | ||
); | ||
|
||
if (isCurrencySymbolLTR) { | ||
return ( | ||
<> | ||
{currencySymbolButton} | ||
{amountTextInput} | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
{amountTextInput} | ||
{currencySymbolButton} | ||
</> | ||
); | ||
} | ||
|
||
TextInputWithCurrencySymbol.propTypes = textInputWithCurrencySymbolPropTypes.propTypes; | ||
TextInputWithCurrencySymbol.defaultProps = textInputWithCurrencySymbolPropTypes.defaultProps; | ||
TextInputWithCurrencySymbol.displayName = 'TextInputWithCurrencySymbol'; | ||
|
||
export default React.forwardRef((props, ref) => ( | ||
<TextInputWithCurrencySymbol | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
forwardedRef={ref} | ||
/> | ||
)); |
45 changes: 45 additions & 0 deletions
45
src/components/TextInputWithCurrencySymbol/textInputWithCurrencySymbolPropTypes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const propTypes = { | ||
/** A ref to forward to amount text input */ | ||
forwardedRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({current: PropTypes.instanceOf(React.Component)})]), | ||
|
||
/** Formatted amount in local currency */ | ||
formattedAmount: PropTypes.string.isRequired, | ||
|
||
/** Function to call when amount in text input is changed */ | ||
onChangeAmount: PropTypes.func, | ||
|
||
/** Function to call when currency button is pressed */ | ||
onCurrencyButtonPress: PropTypes.func, | ||
|
||
/** Placeholder value for amount text input */ | ||
placeholder: PropTypes.string.isRequired, | ||
|
||
/** Currency code of user's selected currency */ | ||
selectedCurrencyCode: PropTypes.string.isRequired, | ||
|
||
/** Selection Object */ | ||
selection: PropTypes.shape({ | ||
start: PropTypes.number, | ||
end: PropTypes.number, | ||
}), | ||
|
||
/** Function to call when selection in text input is changed */ | ||
onSelectionChange: PropTypes.func, | ||
|
||
/** Function to call to handle key presses in the text input */ | ||
onKeyPress: PropTypes.func, | ||
}; | ||
|
||
const defaultProps = { | ||
forwardedRef: undefined, | ||
onChangeAmount: () => {}, | ||
onCurrencyButtonPress: () => {}, | ||
selection: undefined, | ||
onSelectionChange: () => {}, | ||
onKeyPress: () => {}, | ||
}; | ||
|
||
export {propTypes, defaultProps}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'control'
->CONST.PLATFORM_SPECIFIC_KEYS.CTRL.DEFAULT
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I've seen these key constants in the past, but then I forgot all about them. It's fixed now.