element-web/src/utils/Accessibility.js

29 lines
1,015 B
JavaScript
Raw Normal View History

/*
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2019-05-21 02:41:48 +00:00
/**
* Automatically focuses the captured reference when receiving a non-null
* object. Useful in scenarios where componentDidMount does not have a
* useful reference to an element, but one needs to focus the element on
* first render. Example usage: ref={focusCapturedRef}
2019-05-21 15:33:52 +00:00
* @param {function} ref The React reference to focus on, if not null
2019-05-21 02:41:48 +00:00
*/
export function focusCapturedRef(ref) {
2019-05-21 02:41:48 +00:00
if (ref) {
ref.focus();
}
2019-05-17 21:36:28 +00:00
}