-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Desktop: Accessibility: Add error indication on Note properties #11784
Open
pedr
wants to merge
9
commits into
laurent22:dev
Choose a base branch
from
pedr:validate-location-on-note-properties
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
771f9c1
add error identification and error suggestion
pedr f327e87
fixing bug onKey
pedr 4bd9402
add aria invalid
pedr ed6b71a
unnecessary code
pedr 08fbf74
add error description with example
pedr c097154
fixing type
pedr db4bd20
warn color from theme
pedr 3a3eff2
Merge branch 'dev' into validate-location-on-note-properties
pedr 6aa0e98
fixing mistake values are floats, not int
pedr 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ interface State { | |
formNote: FormNote; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied | ||
editedValue: any; | ||
isValid: Record<string, boolean>; | ||
} | ||
|
||
const uniqueId = (key: string) => `note-properties-dialog-${key}`; | ||
|
@@ -56,13 +57,17 @@ class NotePropertiesDialog extends React.Component<Props, State> { | |
|
||
this.revisionsLink_click = this.revisionsLink_click.bind(this); | ||
this.buttonRow_click = this.buttonRow_click.bind(this); | ||
this.locationOnChange = this.locationOnChange.bind(this); | ||
this.okButton = React.createRef(); | ||
this.inputRef = React.createRef(); | ||
|
||
this.state = { | ||
formNote: null, | ||
editedKey: null, | ||
editedValue: null, | ||
isValid: { | ||
location: true, | ||
}, | ||
}; | ||
|
||
this.keyToLabel_ = { | ||
|
@@ -191,6 +196,17 @@ class NotePropertiesDialog extends React.Component<Props, State> { | |
borderColor: theme.dividerColor, | ||
}; | ||
|
||
this.styles_.invalidInput = { | ||
border: '1px solid', | ||
borderColor: 'red', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That should come from the theme |
||
}; | ||
|
||
this.styles_.invalidMessage = { | ||
marginTop: '0.3em', | ||
color: theme.color, | ||
fontSize: theme.fontSize * 0.9, | ||
}; | ||
|
||
return this.styles_; | ||
} | ||
|
||
|
@@ -278,6 +294,24 @@ class NotePropertiesDialog extends React.Component<Props, State> { | |
}); | ||
} | ||
|
||
public async locationOnChange(event: React.ChangeEvent<HTMLInputElement>) { | ||
this.setState({ editedValue: event.target.value }); | ||
if (!event.target.value) { | ||
this.setState({ isValid: { ...this.state.isValid, location: true } }); | ||
return; | ||
} | ||
|
||
if (event.target.value.includes(',')) { | ||
const [lat, log] = event.target.value.split(','); | ||
if (parseInt(lat, 10) < 90 && parseInt(lat, 10) > -90 && parseInt(log, 10) < 180 && parseInt(log, 10) > -180) { | ||
this.setState({ isValid: { ...this.state.isValid, location: true } }); | ||
return; | ||
} | ||
} | ||
|
||
this.setState({ isValid: { ...this.state.isValid, location: false } }); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied | ||
public createNoteField(key: keyof FormNote, value: any) { | ||
const styles = this.styles(this.props.themeId); | ||
|
@@ -290,8 +324,7 @@ class NotePropertiesDialog extends React.Component<Props, State> { | |
let editCompIcon = null; | ||
let editComDescription = null; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied | ||
const onKeyDown = (event: any) => { | ||
const onKeyDown = (event: React.KeyboardEvent) => { | ||
if (event.keyCode === 13) { | ||
void this.saveProperty(); | ||
} else if (event.keyCode === 27) { | ||
|
@@ -317,6 +350,30 @@ class NotePropertiesDialog extends React.Component<Props, State> { | |
}; | ||
editCompIcon = 'fa-save'; | ||
editComDescription = _('Save changes'); | ||
} else if (this.state.editedKey === 'location') { | ||
controlComp = ( | ||
<React.Fragment> | ||
<input | ||
defaultValue={value} | ||
type="text" | ||
ref={this.inputRef} | ||
onChange={this.locationOnChange} | ||
onKeyDown={event => onKeyDown(event)} | ||
style={this.state.isValid.location ? styles.input : { ...styles.input, ...styles.invalidInput }} | ||
id={uniqueId(key)} | ||
name={uniqueId(key)} | ||
aria-invalid={!this.state.isValid.location} | ||
/> | ||
{ | ||
this.state.isValid.location ? null | ||
: <React.Fragment> | ||
<div aria-live='polite' style={styles.invalidMessage}> | ||
{_('Invalid format. E.g.: 48.8581372, 2.2926735')} | ||
</div> | ||
</React.Fragment> | ||
} | ||
</React.Fragment> | ||
); | ||
} else { | ||
controlComp = ( | ||
<input | ||
|
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.
Could this be typed more precisely? At the moment it looks like only the location property is supported?
In which case:
isValid: {
location: boolean;
}